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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:55:07+00:00 2026-06-12T21:55:07+00:00

In my ASP .NET MVC 2 – application, there are several controllers, that need

  • 0

In my ASP .NET MVC 2 – application, there are several controllers, that need the session state. However, one of my controllers in some cases runs very long and the client should be able to stop it.

Here is the long running controller:

    [SessionExpireFilter]
    [NoAsyncTimeout]
    public void ComputeAsync(...) //needs the session
    {
    }

    public ActionResult ComputeCompleted(...)
    {

    }

This is the controller to stop the request:

    public ActionResult Stop()
    {
      ...
    }

Unfortunately, in ASP .NET MVC 2 concurrent requests are not possible for one and the same user, so my Stop-Request has to wait until the long running operation has completed. Therefore I have tried the trick described in this article and added the following handler to Global.asax.cs:

    protected void Application_BeginRequest()
    {
        if (Request.Url.AbsoluteUri.Contains("Stop") && Request.Cookies["ASP.NET_SessionId"] != null)
        {
            var session_id = Request.Cookies["ASP.NET_SessionId"].Value;

            Request.Cookies.Remove("ASP.NET_SessionId");
            ...
        }
    }

This simply removes the session-id from the Stop-Request. At the first glance this works well – the Stop-Request comes through and the operation is stopped. However, after that, it seems that the session of the user with the long running request has been killed.

I use my own SessionExpireFilter in order to recognize session timeouts:

 public class SessionExpireFilterAttribute : ActionFilterAttribute
 {
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext ctx = HttpContext.Current;

        // check if session is supported
        if (ctx.Session != null)
        {
            // check if a new session id was generated
            if (ctx.Session.IsNewSession)
            {

                // If it says it is a new session, but an existing cookie exists, then it must
                // have timed out
                string sessionCookie = ctx.Request.Headers["Cookie"];
                if ((null != sessionCookie) && (sessionCookie.IndexOf("ASP.NET_SessionId") >= 0))
                {

                    filterContext.Result = new JsonResult() { Data = new { success = false, timeout = true }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
                }
            }
        }

        base.OnActionExecuting(filterContext);
    }
}

ctx.Session.IsNewSession is always true after the Stop-Request has been called, but I don’t know why. Does anyone know why the session is lost? Is there any mistake in the implementation of the Stop-Controller?

  • 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-06-12T21:55:09+00:00Added an answer on June 12, 2026 at 9:55 pm

    The session is lost because you removed the session cookie. I’m not sure why that seems illogical. Each new page request supplies the cookie to asp.net, and if there is no cookie it generates a new one.

    One option you could use to use cookieless sessions, which will add a token to the querystring. All you need to do is generate a new session for each login, or similar.

    But this is one of the reasons why session variables are discouraged. Can you change the code to use an in-page variable, or store the variable in a database?

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

Sidebar

Related Questions

ASP.Net MVC Controllers have several methods of forwarding control to another controller or action.
Using ASP.NET MVC there are situations (such as form submission) that may require a
My ASP.NET MVC application uses a data structure that is time costly to create,
ASP.NET MVC 3 can generate scaffold code for us(controllers and views). The generated views
ASP.NET MVC web app that exposes friendly URLs: http://somesite.com/friendlyurl ...which are rewritten (not redirected)
In ASP.NET MVC 3 if you define a section in a view that isn't
ASP.NET MVC 2.0 I'm doing Post-Redirect-Get, if I get errors on post, I need
ASP.NET MVC app, close to completion, then it was decided that it needed a
ASP.Net MVC 3 using C# I currently have a form with some dropdown lists
In ASP.NET MVC, I have a main standard form that posts to an action,

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.