ajax.net调用session和cookie

Ajax.Net在后台调用Session和Cookie比较特殊,需要使用如下的写法:

Cookie:
HttpContext.Current.Response.Cookie[key]

Session:
HttpContext.Current.Session[key]

此外,要使用Session还需要在AjaxMethod特性后加Ajax.HttpSessionStateRequirement参数:

[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public string GetInfo(string a)
{
//do something
}

HttpSessionStateRequirement枚举有:None,Read,ReadWrite,根据你的需要选用即可。

原文地址:https://www.cnblogs.com/tuyile006/p/1853664.html