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 6887253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:51:45+00:00 2026-05-27T05:51:45+00:00

I am using a ActionFilter to check if a User’s session is the most

  • 0

I am using a ActionFilter to check if a User’s session is the most current session for that user. If they have signed in with another session then the old session is invalid. So, I am checking each action as it is called and signing them out if they are not using the most current session. The problem I am having is that my approach does not work with AJAX calls. The normal GET or POST calls work fine.

public class DuplicateLoginFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
        if (user != null)
        {
            if (!PortalDA.GetUserSession(user.UserName).Trim().Equals(HttpContext.Current.Session.SessionID))
            {

                FormsAuthentication.SignOut();
                filterContext.Result = new RedirectResult(@"\Home\SessionExprired");
            }
        }
        base.OnActionExecuting(filterContext);
    }

I guess my biggest problem to solving this is that I get an error but I can’t catch it any where.

I have custom Errors turned On in the webconfig. I am overriding the OnException event in all my controllers. I am also overriding the Application_Error event in the global.asax.

I have stepped through the code, when I make an AJAX call, I return the SessionExpired View. But somewhere after that the error occurs and I can’t step any further. The error is never caught in the error events that were overridden. And I get sent to the custom Error page.

I suspect it has something to do with the HTTPHeaders but I don’t understand enough about them to know how to fix it if it is AJAX call.

Thanks!

  • 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-27T05:51:46+00:00Added an answer on May 27, 2026 at 5:51 am

    Try redirecting using your routes and not hardcoding the url:

    filterContext.Result = new RedirectToRouteResult(
        new RouteValueDictionary(new 
        {
            controller = "Home",
            action = "SessionExpired"
        }
    ));
    

    Then make sure that the SessionExpired action exists on HomeController along with the corresponding view and that this action is hit. Obviously since you are redirecting inside an AJAX call, all that you will get in the success callback of your AJAX call is the HTML of this SessionExpired view passed as argument. Don’t expect the browser to redirect. You will have to use window.location.href to manually redirect the browser. That’s the reason why in this case (the AJAX one) it is better to return a Json result instead of redirecting to a session expired action. Then on the client side you could perform the redirect manually.

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

Sidebar

Related Questions

I have an external-to-my-solution web service that I'm using in an ActionFilter. The action
Currently I have an ActionFilter that gets the current users name from HttpContext and
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C#, I need a class called User that has a username, password, active
I have a project that I've built without using the default template, instead I
Using online interfaces to a version control system is a nice way to have
Using ASP.NET MVC there are situations (such as form submission) that may require a
I have an application that will support multiple sites. The site will be determined
Background: I have an ASP.NET MVC application that wraps controller actions in a TransactionScope
I have an action that looks like this: [Post] [PopulateModelFromId] public ActionResult ChangeName( string

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.