2016-05-24 23 views
0

我正在使用owin cookie身份驗證來保持用戶登錄。但我注意到cookie從客戶端瀏覽器中消失而未過期。登錄cookie在到期前消失

var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); 

     var properties = new AuthenticationProperties() { 
      IssuedUtc = DateTime.UtcNow, 
      ExpiresUtc = DateTime.UtcNow.Add(Startup.CookieAuthenticationOptions.ExpireTimeSpan), 
      IsPersistent = true 
     }; 

     HttpContext.Current.GetOwinContext().Authentication.SignIn(properties, identity); 

啓動:

public class Startup { 
    public void Configuration(IAppBuilder app) { 
     CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; 
     GlobalHost.Configuration.DefaultMessageBufferSize = 100; 
     ConfigureCookie(app); 
     app.MapSignalR(); 
    } 

    public static CookieAuthenticationOptions CookieAuthenticationOptions { get; private set; } 

    public void ConfigureCookie(IAppBuilder app) { 
     CookieAuthenticationOptions = new CookieAuthenticationOptions() { 
      ExpireTimeSpan = TimeSpan.FromDays(7), 
      CookieSecure = CookieSecureOption.SameAsRequest, 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      CookieName = "TokenHandler" 
     }; 

     app.UseCookieAuthentication(CookieAuthenticationOptions); 
    } 
} 

沒有人有任何線索?我並不是百分之百地確信這一點,但那是我得到的感覺,因爲我現在需要更多地簽名。是否有可能新版本的網站可能導致這種情況?

回答

1

假設您確信cookie已正確創建(您可以在瀏覽器分析器上看到它,並且過期日期是正確的),並且您也確定可以在沒有問題的情況下導航網站。 ...

測試:檢查您是否只關閉瀏覽器後關閉cookie ...如果是這種情況,可能是瀏覽器自行設置的原因。有些設置不允許從「會話」到「會話」存儲。