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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with cookies

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
This is the first time I have ever worked with cookies so sorry in advance if this sounds a bit like nonesense.

I want a user to be redirected to a login page if they have not logged in. Once they have successfully logged in, I want to write a cookie that will register the time of this login - and be able to check in an hour if the session is still valid. If it is, refresh the cookie. If not - the user must log in again.

OK - this is what I have so far (straight out of MSDN) in c#:

FormsAuthenticationTicket tktLogin;
string cookiestr;
HttpCookie hcookie;

//create the FormsAuthenticationTicket and the Cookie

tktLogin = new FormsAuthenticationTicket(1, LoginName, DateTime.Now, DateTime.Now.AddMinutes(60), true);
cookiestr = FormsAuthentication.Encrypt(tktLogin);
hcookie = new HttpCookie (FormsAuthentication.FormsCookieName, cookiestr);
Response.Cookies.Add(hcookie);

//redirect the user to the default page

string strRedirect;
strRedirect = Request["ReturnUrl"];
if (strRedirect==null)
strRedirect = "default.aspx";
Response.Redirect(strRedirect, true);

Can someone please tell me if I am at least on the right track and how on earth I go about testing this???

Thanks as always and soz for the newbie question

Craftor :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top