在对Asp.net MVC动作进行Ajax调用时访问会话 [英] Access to session when making ajax call to Asp.net MVC action

查看:55
本文介绍了在对Asp.net MVC动作进行Ajax调用时访问会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

控制器中可用的Session是HttpSessionStateBase.如果您的控制器是从Controller继承的,则可以使用Session[param]base.Session[param]访问它.但是,如果您将Ajax设置为无cookie,则对Ajax可能没有用.

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.

这篇关于在对Asp.net MVC动作进行Ajax调用时访问会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆