我有一个启用 Razor 的应用程序和这样的服务:
public object Post(SelectTerminalRequest request)
{
var location = base.Request.AbsoluteUri.CombineWith(request.TerminalId, "/flights");
if (Request.Cookies.ContainsKey("Terminal"))
{
Request.Cookies.Remove("Terminal");
}
Request.Cookies.Add("Terminal",
new Cookie("Terminal", request.TerminalId.ToString())
{ Expires = DateTime.Now.AddYears(1) });
return new HttpResult(HttpStatusCode.Redirect)
{
Location = location
};
}
但是,当我尝试在我的 Razor 视图中访问该 cookie 时,它是空的:
@{
Cookie cookie;
Request.Cookies.TryGetValue("Terminal", out cookie);
var baseUri = Request.GetApplicationUrl() + "/terminals";
var redirectUrl = cookie != null ? baseUri + "/" + cookie.Value + "/flights" : baseUri;
}
当我浏览我的 cookie 时,我看不到任何内容Terminal
: