Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FormsAuthentication - can't get persistent cookie

Status
Not open for further replies.

tcstom

Programmer
Aug 22, 2003
235
GB
I just can't get my head round persistent cookies when using FormsAuthentication so I hope someone can help. Basically I have a login screen, and I want to create a persistent cookie which holds a few properties of the user, specifically their name, userID and access level. It doesn't matter what I do, my cookies always expire at session end. For example, after authenticating the login I'm using the following code...

Code:
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUser.Text, true));

This should create a persistent cookie. But if I close the browser and re-open it then Context.Request.IsAuthenticated returns false. How can I make a login persiste across sessions? What I'm looking for is direction to a decent tutorial to explain all this stuff, because I can find endless tutorials about the simple authentication and redirection process with FormsAuthentication, but nothing about how to maintain a persistent cookie or add information to the cookie that is created with the GetRedirectUrl method.

Any advice is appreciated.

Tom
emo_big_smile.gif
 
The relevant lines in my web.config are:

Code:
<authentication mode="Forms">
  <forms name="XXXXXX_user" loginUrl="login.aspx" protection="All" timeout="30" path="/" />
</authentication>

My user accounts are in a database. I've tried without the timeout property, but my understanding is that persistent cookies ignore this anyway...

Tom
emo_big_smile.gif
 
Try just using FormsAuthentication.RedirectFromLoginPage(username,true)and see if this will work for you. Everything else looks fine to me.
 
OK, will do. Will have to wait until I get home from work. Meanwhile, if this succeeds in creating a persistent cookie then will I be able to access it from the Response.Cookies collection as normal?

Tom
emo_big_smile.gif
 
Yes you can access this from Response.cookies["cookieName"]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top