[英]OWIN Cookie authentication not working on IIS 8.5
我開發了一個帶有OWIN身份驗證的ASP.NET webapp,它在我的開發機器(Windows 10 / IIS 10)上工作正常,但是當使用IIS 8.5將webapp發布到我的Windows 2012服務器時,cookie身份驗證似乎不起作用。
當我登錄(IsPersistent設置為true)並關閉瀏覽器時,我仍然在我再次啟動瀏覽器時登錄,所以沒關系。 但是,當我重新啟動IIS並啟動瀏覽器時,我必須再次登錄。
我創建了一個非常簡單的應用程序來測試它,使用以下代碼:
Startup.cs
public void ConfigureAuthentication(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Login"),
CookieName = "ThisIsTheAuthCookie"
});
}
AuthenticationController.cs
public ActionResult Login(string userName, string password)
{
//For testing purposes every user/pwd is fine
var identity = new ClaimsIdentity(new [] { new Claim(ClaimTypes.Name, userName), },
DefaultAuthenticationTypes.ApplicationCookie,
ClaimTypes.Name, ClaimTypes.Role);
HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties { IsPersistent = true }, identity);
return RedirectToAction("index", "home");
}
甚至Chrome也會顯示Cookie,但看起來OWIN在IIS 8.5上沒有使用它:
有人知道問題是什么嗎?
謝謝,丹尼
您可以嘗試一些事情並分享結果: - 1.重新啟動IIS,保留User-Agent。 看看你現在是否登錄。 2.啟用Katana日志記錄並在日志中檢查此警告/錯誤。
對此有任何結果嗎?
對我來說,看起來你有可用會話ID的cookie,但IIS服務器在這個會話上不再知道。 您確定在IIS服務器上保留會話嗎? (而不是'正在處理')
您可以在IIS配置中的“會話狀態”下找到該選項。 請參閱TechNet文章IIS
問題已經解決了。 我不得不在web.config中添加MachineKey元素!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.