Authenticated users after IIS reset in .net
I'm building a .net web app and using Forms authentication with cookies to remember if the user is signed in or not:
<authentication mode="Forms">
<forms timeout="4320" cookieless="UseCookies" loginUrl="~/account.aspx" name="test" slidingExpiration="true" />
</authentication>
But after building, changing the web.config or doing an IIS reset, the first page I load shows I am 开发者_开发知识库not signed in. But if I refresh the page again it then shows I'm signed in, even if I didn't do anything.
So it seems it remembers I was signed in, but only after the first page load.
Is that usual? Do I have something misconfigured in the web.config? Is this a localhost issue only?
Ok, this was my own bonehead fault of course. Turns out in my web.config I had the setting:
<appSettings configSource="appSettings.config" />
The problem is that appSettings.config didn't exist in my project. After I removed this line (it was from boilerplate code and didn't need it), it worked find.
So apparently on the first load .net was angry about this file not existing as it was trying to load up the config for the first time, but after the first load it didn't care anymore (that's about as technical as I can get).
The problem is the session being reset. Although you are having the cookies, you need to do one more thing.
On your validate user section, make sure the remember me setting is checked, ie
FormsAuthentication.RedirectFromLoginPage ("TheirUserId", Persist.Checked)
its the Persist.Checked that you need to ensure is true. Refer to http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx for further information
精彩评论