开发者

Session timeout handled, but still not working in asp.net?

I set timeout for 30 mins in web.config like below

    <forms name=".FormsAuth" loginUrl="/Login.aspx" timeout="30" protection="All" 
slidingExpiration="true" >

    <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" 
stateNetworkTimeout="300" sqlCommandTimeout="300"  sqlConnectionString="data 
source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="30" />

In master page page . I set SeTtime of 30 mins so it can redirect login page.

Dim sessionExpiredUrl As String = Request.Url.GetLeftPart(UriPartial.Authority) & "/labor"
Dim script As New StringBuilder()
script.Append("funct开发者_StackOverflowion expireSession(){ " & vbLf)
script.Append(String.Format(" window.location = '{0}';" & vbLf, sessionExpiredUrl))
script.Append("} " & vbLf)
script.Append(String.Format("setTimeout('expireSession()', {0}); " & vbLf, Me.Session.Timeout * 60000))
' Convert minutes to milliseconds 
Me.Page.ClientScript.RegisterClientScriptBlock(Me.[GetType](), "expirescript", script.ToString(), True)

It is working fine . after 30 mins it is redirect to login page. But If I click pages that have session object at "25 MINS". It is throwing exception [NullReferenceException: Object reference not set to an instance of an object.].

I don't understand why session objects becoming "Null" before 30 mins and how to handle this?

Edit: Error happening here.

 mUser = CType(Session("user"), User)
Dim processTime As String = mUser.GetLastProcessTime(lastProcessTime) // Error happening here


Since you are using InProc, possibly your app pool is reseting or shutting down due to inactivity, and that invalidates the session. Take a look at this article to see if it is your problem.


It's because you set SlidingExpiration = true and Sliding expiration resets the expiration time for a valid authentication cookie if a request is made and more than half of the timeout interval has elapsed.

http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.slidingexpiration.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜