我正在尝试在测试此代码时在Web服务中创建一个cookie,当我从aspx页面调用它时,它会返回" Done"但是没有创建cookie
[WebMethod]
public string CreateCookie()
{
var Cookies = new HttpCookie("test123");
Cookies.Value = "123";
Cookies.Expires = DateTime.Now.AddHours(1);
HttpContext.Current.Response.Cookies.Add(Cookies);
return "Done";
}
我的要求
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create("http://localhost/testservice.asmx/CreateCookie");
myRequest.Method = "POST";
myRequest.ContentLength = 0;
HttpWebResponse response = myRequest.GetResponse() as HttpWebResponse;
StreamReader reader = new StreamReader(response.GetResponseStream());
Response.Write(reader.ReadToEnd());