我有一个asmx webservice,它有一个web方法,我通过jquery ajax调用它,它返回一个字符串,我想从这个方法读取和编辑cookie,我知道我可以读取这样的cookie :
HttpContext.Current.Request.Cookie["cookie_name"];
但是当我试图更改此Cookie的值时,这不起作用:
HttpContext.Current.Response.Cookie["cookie_name"].Value = "some_value";
所以让我们说这是我的功能:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod(EnableSession = true)]
public string myMethod()
{
//...some actions
if(HttpContext.Current.Response.Cookie["cookie_name"] != null)
{
HttpContext.Current.Response.Cookie["cookie_name"].Value = "some_value";
}
return "";
}
这是我的ajax电话
$.ajax({
type: "POST",
url: "/route-to/myMethod",
data: JSON.stringify({ }),
contentType: "application/json",
charset: "utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
}
});
此代码中究竟出了什么问题?