MVC web app in global.asax when session time how to get cookie value

Everyone, I'm a new person. Hope you could help me, thanks in advance.

Now I am facing a problem for an MVC web application in global.asax, when the session time, how to get the cookie value that I have set for it in some controller;

I've tried in the case of Session_End () & Session_Start (), but I'm not sure how to get the cookie value.

+3


source to share


1 answer


You cannot access the cookie from Session_End because Session_End is not triggered from the user's request, which means it cannot read anything that is stored in the user's browser. But you can store some data in the Session object:

//Inside your controller
Session["YourData"] = "Some value";

      

And then get it in the Session_End event:



void Session_End(object sender, EventArgs e)
{
    var someValue = (string)Session["YourData"];
    //do something with someValue
}

      

I hope this helps

+1


source







All Articles