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

  • SEARCH
  • Home
  • 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 6686351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:09:42+00:00 2026-05-26T05:09:42+00:00

In my app (ASP.NET MVC 3 RAZOR), when a session expires and the user

  • 0

In my app (ASP.NET MVC 3 RAZOR), when a session expires and the user tries to access something, it redirects them to the login page to re-login.

This is fine, but when calling from ajax requests (e.g. if the user has left their screen for a while with no activity), it will load the login form in the ajax request… Which is not what I want to happen.

What is the best way of dealing with this? Ideally I’d like to show a modal if the session has expired so the user can’t access other areas. So even if they leave the screen some jQuery will have checked the session and then applied a modal saying ‘Session Expired’

How would I do this?

e.g.

if(SESSION HAS EXPIRED) { showModal(); }
  • 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-26T05:09:42+00:00Added an answer on May 26, 2026 at 5:09 am

    I can see two separate addressable issues here, so I will discuss them each separately.

    Login returned as AJAX result:
    Rather than just return the login screen, return a message indicating that the session has expired. If your AJAX receives such a message, it knows the user needs to log back in. At this point, you can do something like

    window.location = loginpageurlhere;
    

    Alternately, you can check your AJAX response to see if it is an expected response or if it is the login page. If it is the login page, use the above suggestion.

    Display dialog if user is inactive for too long:
    For this, you need to know how long the user is inactive. You can do this in a couple different ways, one of which is as follows:

    • When the page loads, initialize a variable to use as a countdown.
    • Set a timer that will decrement the counter every time it runs out of time, and then restart.
    • If the counter ever hits zero, display the dialog and have the user log back in.
    • Every time a valid activity occurs (AJAX post or whatever else you may have), reset the counter.

    You could use either, of these methods, although if you are concerned about protecting data at an unattended machine, the second method would be best, since you can block the screen and only display the dialog, and it will happen while the user is away, whereas the first method can’t do anything until a user actually attempts to perform an action on your page.

    • 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 app with Razor. I try to access a collection
In my ASP.NET MVC app, I have a fairly complex edit page which combines
I am developing an e-commerce app using asp.net mvc. After user successfully logged into
In my ASP.net MVC App (using Razor views) I have a ProductDetails view. This
For my ASP.NET MVC 3 app (using Razor) my web.config has this: <profile> <providers>
I just upgraded an ASP.NET MVC app to version 3.0 and Razor. I have
My web app solution consists of 3 projects: Web App (ASP.NET MVC) Business Logic
I keep getting this error when I run my web app (asp.net mvc) in
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually
I'm creating a small app in ASP.NET MVC that generates ics (iCal) files based

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.