AjaxPro为什么不能获取cookie?
下面这段代码并不能得到Request.Cookies[ "id "].Value的值,请问该如何解决啊?
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
}
[AjaxPro.AjaxMethod]
public string GetNum()
{
string sqlURL = ConfigurationManager.AppSettings[ "DB_ConnectString "];
DBServer.DBSqlServer dbs = new DBServer.DBSqlServer();
Response.Cookies[ "id "].Value = "836 ";
dbs.ConnOpen(ConfigurationManager.AppSettings[ "DB_ConnectString "]);
SqlDataReader dr = dbs.GetReader(string.Format( "select count(*) as num from OA_TB_MESSAGE where USERID= '{0} ' and STATUS=0 ", Request.Cookies[ "id "].Value));
if (dr == null)
{
return "0 ";
}
string result = " ";
if (dr.Read())
{
result = dr[ "num "].ToString();
}
dbs.ConnClose();
return result;
}
------解决方案--------------------使用[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
就可以这样存取Session的值了: this.Session[ "0 "].ToString().
在AjaxMethod中使用Cookie是不能使用 "this "的引用存取cookie ,你必须使用HttpContext.Current例如: HttpContext.Current.Request.Cookies[Name].Value