locked
Session_End cannot be fired in global.asax in Web API RRS feed

  • Question

  • I want to run Session_End() in global.asax in Web API, But I do not know how to enable it?

    Currently the Session_Start is ok. Thanks for you help!

    public class WebApiApplication : System.Web.HttpApplication
    	{	
    
            public override void Init()
            {
                this.PostAuthenticateRequest += MvcApplication_PostAuthenticateRequest;
                this.AuthenticateRequest += Session_Start;
                base.Init();
            }
    
            void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
            {
                System.Web.HttpContext.Current.SetSessionStateBehavior(System.Web.SessionState.SessionStateBehavior.Required);
            }
    
            protected void Application_Start()
    		{
    			GlobalConfiguration.Configure(WebApiConfig.Register);
    		}
    protected void Session_End(Object sender, EventArgs e)
    		{
    }
    }

    • Moved by CoolDadTx Friday, June 15, 2018 1:49 PM ASP.NET related
    Friday, June 15, 2018 8:04 AM

Answers

  • You would have had to do something with Session_Start() actually put something into session before Session_End() will firer.

     protected void Session_Start(object sender, EventArgs e)
     {
               Session["EhapUser"] =    UserServiceManager.GetEHAPUser(HttpContext.Current.User.Identity.Name.Remove(0, 5));
     }

    WebAPI issues can be addressed at the ASP.NET forms, which there is a forum in the forums 

    https://forums.asp.net/

    • Marked as answer by JoeyWang Wednesday, June 20, 2018 7:39 AM
    Friday, June 15, 2018 9:51 AM
  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by JoeyWang Wednesday, June 20, 2018 7:39 AM
    Friday, June 15, 2018 1:49 PM

All replies

  • You would have had to do something with Session_Start() actually put something into session before Session_End() will firer.

     protected void Session_Start(object sender, EventArgs e)
     {
               Session["EhapUser"] =    UserServiceManager.GetEHAPUser(HttpContext.Current.User.Identity.Name.Remove(0, 5));
     }

    WebAPI issues can be addressed at the ASP.NET forms, which there is a forum in the forums 

    https://forums.asp.net/

    • Marked as answer by JoeyWang Wednesday, June 20, 2018 7:39 AM
    Friday, June 15, 2018 9:51 AM
  • Please post questions related to ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by JoeyWang Wednesday, June 20, 2018 7:39 AM
    Friday, June 15, 2018 1:49 PM
  • The address is only for asp.net forums. Then how can I find other forums? such as c# winform, WPF, WCF, and so on? thanks.
    Wednesday, June 20, 2018 7:46 AM
  • The address is only for asp.net forums. Then how can I find other forums? such as c# winform, WPF, WCF, and so on? thanks.

    Each one has their own MSDN forum, use Bing or Google to find them.
    Monday, June 25, 2018 12:38 PM
  • Thanks!
    Wednesday, June 27, 2018 8:58 AM