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
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
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>"
};
}