[WebMethod]
public static void SetTheme(string theme)
{
Guid studentIdentifier = SessionData.LoggedInUser.Identifier;
Student student = (Student)ItemFactory.GetItem(studentIdentifier);
student.Theme = theme;
}
Run Code Online (Sandbox Code Playgroud)
我想在这个WebMethod的末尾更改名为"theme"的cookie.我怎么能做到这一点?必须在此处设置cookie,而不是通过JavaScript.这是一项要求.谢谢
您可以访问webMethod中的HttpContext,并从那里访问响应对象.
var response = HttpContext.Current.Response;
Run Code Online (Sandbox Code Playgroud)
HttpResponse对象允许您使用响应访问发送到浏览器的cookie:
if(response.Cookies["theme"]!=null)
response.Cookies["theme"].Value = myValue;
Run Code Online (Sandbox Code Playgroud)
在MSDN文档使一个很好的工作,解释它.您也可以使用HttpContext.Current.Request访问请求cookie
| 归档时间: |
|
| 查看次数: |
5589 次 |
| 最近记录: |