我的Api控制器
public class UserController : ApiController
{
public HttpResponseMessage Get()
{
var response = new HttpResponseMessage();
var valueSession = new NameValueCollection();
valueSession.Add("user_id", 1);
CookieHeaderValue cookie = new CookieHeaderValue("session", valueSession);
cookie.Expires = DateTimeOffset.Now.AddDays(2);
cookie.Domain = Request.RequestUri.Host;
cookie.Path = "/";
response.Headers.AddCookies(new CookieHeaderValue[] { cookie });
return response;
}
}
我的控制器 - 我需要检索我从API设置到此控制器的cookie。有什么建议吗?
public class UserController : Controller
{
// GET: User
public ActionResult Login()
{
return View();
//do something
}
}
答案 0 :(得分:0)
试试这个:
public ActionResult Login()
{
var userIdVal = Request.Cookies["session"].Values["user_id"];
return View();
//do something
}