Can you return cookies when returni开发者_运维技巧ng an MVC2 Json result?
Yes - Not via the json result but you can simply add in your same controller method Response.Cookies.Add() and they will be added.
Note: that in the an Async action you will need to set the response cookie in the completed method.
Try this:
public ActionResult GetCookies()
{
var cookies = from c in Request.Cookies.AllKeys
select new {Key = c, Value = Request.Cookies[c].Value};
return this.Json(cookies);
}
精彩评论