开发者

Problem: control Session timeout

开发者 https://www.devze.com 2023-04-08 10:39 出处:网络
My session renews every 20 minutes. I\'ve set timeout to 300 minutes but still it renews probably because Application Pool recycles.

My session renews every 20 minutes. I've set timeout to 300 minutes but still it renews probably because Application Pool recycles.

I am storing UserId which is Guid in Session which returns null. Problem is when I use Membership using

Membership.GetUser().ProviderU开发者_JS百科serKey

it works fine. But obviously it makes a database call. How can I prevent this problem from happening? Why does Membership.GetUser().ProviderUserKey succeeds whereas Session doesn't?


In order to complete Jan's and Neil's answers, you should look at your web.config and set both timeouts (sessionState and authentication)

<sessionState timeout="300"/>

Sessionstate timeout specifies the number of minutes a session can be idle before it is abandoned. The default is 20.

<authentication mode="Forms">
  <forms loginUrl="Login.aspx"  timeout="300" />
</authentication>

Forms timeout is used to specify a limited lifetime for the forms authentication session. The default value is 30 minutes. If a persistent forms authentication cookie is issued, the timeout attribute is also used to set the lifetime of the persistent cookie.


Your session may still be alive (if you set it to 300 minutes) but the ASP.NET membership could be expiring?

Have you increased the authentication timeout too?

<authentication mode="Forms">
  <forms loginUrl="Login/" timeout="180"/>
</authentication>


You are mixing authentication and session. These are two completely different concepts. GetUser() return the currently authenticated user form your MemberShipProvider.

Session and authentication have different timeouts - so its valid that your session times out but the user is still authenticated.

0

精彩评论

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

关注公众号