我有發送身份驗證cookie到ASP.NET MVC應用程序,用作後勤應用ASP.NET應用程序。ASP.NET MVC 4餅乾消失
我添加了一個全局篩選器來檢查身份驗證Cookie每個控制器動作。如果cookie存在,它允許用戶進入頁面。
的代碼看起來是這樣的:
public class SecurityFilter : FilterAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// TODO: For some reason .AUTHCookie cookie isn't exist in request context of filter,
HttpCookie cookie = filterContext.RequestContext.HttpContext.Request.Cookies[".AUTHCookie "];
if (cookie != null) {
從另一個方面,我可以看到從ASP.NET應用程序中Application_BeginRequest
事件在Global.asax文件發送的cookie。
在哪裏,爲什麼餅乾消失了?在MVC請求處理管道的哪一部分丟棄了Cookie?
protected void Application_BeginRequest(object sender, EventArgs e)
{
var cookies = HttpContext.Current.Request.Cookies;
// HERE I CAN SEE BOTH cookies. In filter action only one cookie was found. The authentication cookie is thrown somewhere ...
}
確保cookie路徑爲「/」,它有足夠的到期日期。 – Nick
你是什麼意思的單詞「足夠」?是{01/01/0001 00:00:00}是否足夠? – StringBuilder
嘗試期滿設定成類似'DateTime.UtcNow.AddDays(1);'可能是該瀏覽器認爲與日期時間作爲上述過期該cookie。 – Nick