How show popup from ActionFilter if session expires in mvc
Hi,I have contoller and i have created a ActionFilterAttribute for page go direct login page. but if session is expired then display message as like 'your session has been expired, please re-login page'. My coding is working, but our project manager tell me display message before page redirect to login.
any idea so i can set in _layout.cshtml or else. I got in following javascript code internet, but is not working..
public class SessionExpireAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
if (HttpContext.Current.Session["userName"] == null)
{
filterContext.Result = new RedirectResult("~/Home/Index");
return;
}
base.OnActionExecuting(filterContext);
}
}
JavaScript:
=======
<script type="text/javascript">
$(document).ready(function () {
var SessionValue = '@Request.RequestContext.HttpContext.Session["YourSessionKey"]';
if (SessionValue == "") {
alert("your session is expired please try to Re-login");
window.location.href = "~/home/login";
}
});
</script>