You must Sign In to post a response.
  • Category: ASP.Net MVC

    How show popup from ActionFilter if session expires in mvc

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


    <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";
  • #769726
    if you would have mention what is happening after your session get expired with the above logic then we could provide correct solution. However, by reading the above post understood that your message not showing instead it is redirecting to Login page when session get expired.

    so, you can try with callback function i.e write a call back function with action with redirect login page logic. and invoke that function after you message displayed and closed by end user.

    secondly try with confirm() function instead of alert() function by assigning user input value to some variable . so that, you can verify that variable value and then redirect to login page

    hope the above solutions may help you.

    B.Ramana Reddy

  • Sign In to post your comments