How “Session_Start” in Global.Asax works ?. MVC

一笑奈何 提交于 2019-12-11 11:40:27

问题


I'am trying uderstand how "Session_Start" in Global.Asax works. Let's say I've got few pages on my website. For example: I'am entering on "Page A", then function "Session_Start" is firing. Then I'am going to "Page B", and what than ?. Function will firing again, or not ?. I'am trying to write code which will check that cookie "User" exist, and if exist, code will return Session["userName"] variable, but I'am not sure is "Session_Start" good place for that..


回答1:


If you want to make session unlimited, you can use cookies. Which I think you are using, you mentioned that in your original query.

Session_End is fired when user logs out, closes browser to end the session or session times out.

You can keep the cookie on user's browser. And check the cookie in Session_Start for valid values. And resume the session for the user.

You can also increase the session timeout from server configuration.




回答2:


No it will not fire again, for second page. Session_Start fires the first time when a user's session is started

You can use this to check user cookie and save the result to session variable to access in further pages.



来源:https://stackoverflow.com/questions/25445912/how-session-start-in-global-asax-works-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!