ASP.Net Membership Forms Authentication Cookie clears on Application Pool Recycle in IIS

mikehell
 
on Jan 28, 2013 07:57 AM
5028 Views

Hello,

I use Form Based Authentication in my site
In my login page I have:

FormsAuthentication.SetAuthCookie(user.userName, true)
 

When I want to check if the user is authenticated I do: 

HttpContext.Current.User.Identity.IsAuthenticated
 

This is working for me most of the times
The problem is that sometimes after 5 hours or something after 30 hours
The Application pool gets restarted for some reason (I’m on a shared server)
And after that the “User.Identity.IsAuthenticated” returns with false, every time until the user logs in again.

This is strange to me because I can see that the client still have the persistent authCookie so why the user is not authenticated ?

My Web.Config reference:

<authentication mode="Forms">
<forms
name="AuthCookie"
loginUrl="~/mySite/ManageLogin.aspx"
timeout="5256000"/>
</authentication>

<sessionState mode="InProc" timeout="180"></sessionState>
 

 

Any help will be much appriciated

Best regards
mike

Download FREE API for Word, Excel and PDF in ASP.Net: Download
mikehell
 
on Jan 30, 2013 02:46 AM
on Jan 30, 2013 02:49 AM

Ok after countless days i finaly find what causing the authentication cookie to disconnect.

My problem due to the automatic generation of the machinekey at the application start i can prevent that by specifying  machinekey in web.config

you can see the problem in my site Mentallica


<machineKey
    validationKey="MY_KEY"
    decryptionKey="MY_KEY"
    validation="SHA1"
    decryption="AES" /> 

 

Thank you mudassar your help was very appreciated.