Hi
I Use HttpContext.Current.Session int my project ,when I login succeed,I Assign values to the AbpSession object's properties , but when I refresh my page, abpSession object's properties always is null . but sometimes it's ok .how can I Keep Session StatećDo I need to Assign values in Application_BeginRequest(AbpWebApplication ) method ?
thank you
3 Answer(s)
-
0
IAbpSession's setters are readonly. How do you assign? Have you implemented IAbpSession for your own project? If so, no problem. In this implementation, you can get from Session.
Are you creating your actions/methods async? If so, HttpContext.Current may not be reached in async code sometimes.
If you set AbpSession class properties;
- if your session class is transient, it's created per injection and setting it meaningless since when you inject it you will get a new instance and UserId will be null.
- if it's singleton, it's shared by all concurrent requests !! So, it should not be singleton.
You can get from ASP.NET's Session by implementing IAbpSession. That's safer.
-
0
Thank you for your answer,I have modified my code.
public int? UserId { get { var userId = HttpContext.Current.Session["UserId"]; if (userId == null) { return null; } return Convert.ToInt32(userId); } set { throw new NotImplementedException(); } }
but I'm worried about high concurrency and Multithreading, session will have problem,And mobile App can use like this?
-
0
Hi,
AspNet's Session will not be problem in multi-user environment. But this is AspNet's issue, not related to ABP :)
I don't suggest to use Session ! Instead, get UserId from cookie or a token (for token based auth for mobile apps).