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
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