开发者

MVC2 Json result - include cookies?

开发者 https://www.devze.com 2023-03-10 14:02 出处:网络
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 add

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

精彩评论

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

关注公众号