2014-06-20 91 views
1

我已啓用與剃刀的應用程序沒有設置和這樣的服務:ServiceStack Cookie的瀏覽器

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

然而,當我嘗試訪問該cookie在我的Razor視圖,其空:

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

當我瀏覽了我的餅乾,我沒有看到任何與Terminal

enter image description here

回答

3

您肯定會爲此嘗試,但我相信,但添加Cookie應位於Response,您使用的是Request對象。 :)別擔心我也這麼做了!

Response.SetCookie("Terminal", request.TerminalId.ToString());