Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3440864
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:29:00+00:00 2026-05-18T08:29:00+00:00

I have a .NET MVC application which makes extensive use of AJAX and modal

  • 0

I have a .NET MVC application which makes extensive use of AJAX and modal windows. I have an action filter that handles the expiration of a user’s session which redirects to the login page. However, if the request is made from the modal window, the action result that is returned is the login page which then loads in the modal window.

I have been trying to find a way to either redirect the main page to the login when the session expires but I have had no such luck as the Session_End event is fired form the server and I have no access to the Response object. I was wondering if anyone else has encountered a problem like this, and if so, how did you overcome it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:29:00+00:00Added an answer on May 18, 2026 at 8:29 am

    I think I finally figure out a solution for this. While its not as elegant as I had hoped, it works (which is more than I have found so far). The solution lies around the OnBegin AjaxOption and some Jquery. My ActionLink (it could also be an Ajax.BeginForm that this is applied to) looks like this

    <%= Ajax.ActionLink("Do Ajax Function", "AjaxAction", new { }, new AjaxOptions { OnBegin="check_session", OnSuccess = "ajaxSuccess", UpdateTargetId = "update_container"}, new { })%>  
    

    I have a controller action in my Account controller that checks session, in my case I am storing the user object so i check to see if it is null, and returns ‘True’ or ‘False’ as content. The OutputCache is important otherwise your results will be cached.

    [OutputCache(Duration=0, VaryByParam="None")]
            public ActionResult CheckAjaxSessionExpired()
            {
    
                bool _sessionExpired = false;
                if (Session["User"] == null)
                {
                    _sessionExpired = true;
                }
    
                return Content(_sessionExpired.ToString());
            }
    

    The last part is the check_session function specified as the OnBegin handler. The Jquery ajax call hits the session check action and checks the response. If the response is ‘True’ (meaning the session has expired), it sets the location of the page back to the home page (or google in this case).

    function check_session(){
    
            var url = '<%= Url.Action("CheckAjaxSessionExpired", "Account") %>';
    
    
            //GET CHECK SESSION
            $.ajax({
                url: url,
                success: function(data) {
    
                    //alert(data);
    
                    if (data == "True"){
                        document.location = "http://www.google.com";
                    }
                },
                error: function() { alert("there was a problem loading the ajax session check"); }
            });
        }
    

    There are several things to remember if using this method. The first is that this will run asynchronously. If you have data sensitive code that you are calling you will still need to perform a server side check on session. This code is intended to simply redirect to the login page (or home page) if the session is expired during an ajax call. The second thing is that the check_session function will need to be wired into the OnBegin event of all of your Ajax calls. If anyone has any tips or suggestions for improving this method, I would love to hear them. I hope this helps somebody.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC application which is build up as an assembly that
I have an ASP.NET MVC 3 application which has a post action called Create
We have an ASP.NET application on ASP.NET 4.0 using MVC 3 which uses Windows
i have a asp.net mvc application which uploads several xml files that are used
I have an ASP.NET MVC web application that makes REST style web service calls
I have an .NET 4.0 ASP.NET MVC application, which also hosts a Workflow Foundation
In the asp.net mvc 3 application I have two views which have the same
I created a simple ASP.NET MVC version 1.0 application. I have a ProductController which
I have an ASP.NET MVC application that uses Fluent NHibernate and AutoMapper. I am
I have an ASP.NET MVC 2 application which in part allows a user to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.