Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When user log in my web,I set the cookie's timeout to be 30 min,after timeout,when user want to go to page B from page A,I will check the cookie time out and return the javascript to the brower,what's wrong with my codes?It seems that I return the content because all the codes below will display in the browser but not execute(and I have to refresh the url and is OK).

Method 1:not work

C#
public override void OnAuthorization(AuthorizationContext filterContext)
 {
    var url = string.Format("{0}?ReturnUrl={1}",
              FormsAuthentication.LoginUrl,
              filterContext.HttpContext.Request.RawUrl);
    if (SessionHelper.Get("UserName") == null)
    filterContext.HttpContext.Response.Write(
     "<script>alert('Login overtime!Loggin again please!');
     window.location.href='"+url +"';</script>");
 }

Method 2:not work
C#
public override void OnAuthorization(AuthorizationContext filterContext)
  {
     var url = string.Format("{0}?ReturnUrl={1}",
               FormsAuthentication.LoginUrl,
               filterContext.HttpContext.Request.RawUrl);
     if (SessionHelper.Get("UserName") == null)
      filterContext.Result = new ContentResult
       {
        ContentType = "text/html",
        Content = "<script>alert('Login overtime!Loggin again please!');
       window.location.href='" + url + "';<script>"
       };
    }
Posted
Updated 26-Feb-14 4:11am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900