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

    Use session after Response.End()

    Response.End() has been used for downloading excel.
    So once the Response.End() has been called, I could not
    call another function which uses session. Since session is getting clear.

    Nutshell: Response.End() clearing session.

    How to use session even after Response.End() has been used
  • #768784
    Hi,

    The Response.End() functionality will kill the current session. The reason we are calling this functionality is to clear all the events or values which stored and making end to the client request or server response.
    You can do one thing if you still want to store your session values.
    Save the session Variables in Application Variables and you can use your application variables until you close the entire application but the problem is in multiuser application this is tedious task because we need to identify for each unique user.

    The Other option is declaring the variable in the OnSession Event in Global.asax
    This will function will get triggered and create the session values each time it get cleared.


    public void Session_OnStart()
    {
    }

    Thanks,
    Mani

  • #768804
    Hai Lily,
    You can use HttpApplication.CompleteRequest instead of Response.End(). This will make the request complete but still the session will be alive.
    Also you can have a flag which will indicate that whether you need to end the response or not. So when the request si complete and other things are done, you can call the Response.End() so that Session will also be cleared.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #768806
    Hi,

    You couldn't use or call anything after Response.End() method, that is the default behavior of this.

    If you want to use or perform some action, my suggestion is perform the same action before Response.End() method itself.

    Hope this helps you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments