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,根据你的需要选用即可。

posted @ 2010-10-17 16:15  小y  阅读(876)  评论(0编辑  收藏  举报