0
我必須在我的網站上設置Cookie域,因爲我必須在我的子域中共享身份驗證Cookie。設置CookieDomain導致登錄失敗
當我設置此屬性時,網站仍然可以登錄用戶,但發生了一些奇怪的事情。登錄操作似乎沒有問題,因爲登錄返回成功,但是當我嘗試將用戶重定向到安全操作時,他會自動重定向回登錄頁面。我懷疑有些作品遺漏了。
我已經創建了一個簡單的測試項目,使用帶有認證的基本MVC模板,並且只更改了CookieDomain,如下所示。
ConfigureAuth(Startup.Auth.cs)
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
},
CookieDomain = "localhost" // ****** here is my change
});
正如我所說的應用程序的其餘部分是默認的代碼和下面的代碼行的結果是成功的回報。
登錄(AccountController.cs)
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
我不成功嘗試設置CookieDomain爲 「.localhost」 我也試圖設置Cookie路徑爲 「/」。
見http://stackoverflow.com/questions/34069864/making-my-cookies-work-in-mvc?noredirect=1#comment55893396_34069864答案。 –
@RDay - 在本地主機環境中將CookieDomain更改爲「」!韓國社交協會! –