Answer the question
In order to leave comments, you need to log in
HttpContext.Current.Session?
Hello. Not so long ago I ran into an incomprehensible problem on the site - there is an asp.net mvc project, there is a single-tone SiteUser class through which all work with services is carried out.
upon successful authorization, the current user is stored in the session collection:
- static readonly string sessionKey = "SiteUser";
- public static SiteUser Create()
- {
- SiteUser.Current = new SiteUser();
- return SiteUser.Current;
- }
- public static SiteUser Current
- {
- get
- {
- if (HttpContext.Current.Session == null || HttpContext.Current.Session[sessionKey] == null)
- {
- throw new SiteUserAutorizationExeption();
- }
- return HttpContext.Current.Session[sessionKey] as SiteUser;
- }
- set
- {
- if (!HttpContext.Current.Session == null)
- {
- HttpContext.Current.Session[sessionKey] = value;
- }
- }
- }
- while the session is active, the FormsAuthenticationTicket has not expired.
- HttpContext.Current.Session[sessionKey] == null
- <sessionState mode="InProc" timeout="20" />
Answer the question
In order to leave comments, you need to log in
Yes, I probably won’t help much, but I’ll advise elementary logging. The first is the Session_Start and Session_End methods and encapsulate the writing/reading/deleting of values from the session and logging all actions. I hope someone will offer a more constructive solution.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question