开发者

MVC2 Json result - include cookies?

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);
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜