1

I have an application with Razor Enabled and a service like this:

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

However, when I try and access that cookie in my Razor View, its empty:

@{
     Cookie cookie;
     Request.Cookies.TryGetValue("Terminal", out cookie);
     var baseUri = Request.GetApplicationUrl() + "/terminals";
     var redirectUrl = cookie != null ? baseUri + "/" + cookie.Value + "/flights" : baseUri;
 }

When I browse my cookies, I don't see anything with Terminal:

enter image description here

Scott
  • 21,211
  • 8
  • 65
  • 72
CallumVass
  • 11,288
  • 26
  • 84
  • 154

1 Answers1

4

You'll kick yourself for this one, I am sure, but adding cookies should be on the Response, you used the Request object. :) Don't worry I've done that too!

Response.SetCookie("Terminal", request.TerminalId.ToString());
Scott
  • 21,211
  • 8
  • 65
  • 72