在对Asp.net MVC操作进行ajax调用时访问会话

时间:2022-12-04 16:38:05

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.

我有一个使用ajax请求调用的控制器操作,但是当我尝试访问会话(HttpContext.Session [“key”])时,我没有填充任何会话密钥。当我使用ajax拨打电话时,如何才能访问会话密钥。

2 个解决方案

#1


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.

控制器中的可用会话是HttpSessionStateBase。如果控制器继承自Controller,则可以使用Session [param]或base.Session [param]访问它。但是,如果你设置了无cookie,这对Ajax来说可能毫无用处。

#2


0  

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.

很难弄清楚为什么你的会话没有填充Ajax调用。我只能告诉你,你的会话应该填充Ajax调用。

#1


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.

控制器中的可用会话是HttpSessionStateBase。如果控制器继承自Controller,则可以使用Session [param]或base.Session [param]访问它。但是,如果你设置了无cookie,这对Ajax来说可能毫无用处。

#2


0  

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.

很难弄清楚为什么你的会话没有填充Ajax调用。我只能告诉你,你的会话应该填充Ajax调用。