问题
i have a controller action being called using an ajax request, but when i tried to access session (HttpContext.Session["key"]), i dont have any of my session keys populated. How can i have access to my session keys when i make a call using ajax.
回答1:
The available Session in the controller is the HttpSessionStateBase. You can access it using either Session[param]
or base.Session[param]
if your controller inherits from Controller. But this may be useless with Ajax if you have it set cookieless.
回答2:
It's difficult to figure out why your session is not getting populated for Ajax calls. I can only tell you that your session should get populated for Ajax calls.
来源:https://stackoverflow.com/questions/1897293/access-to-session-when-making-ajax-call-to-asp-net-mvc-action