7
Tôi cố gắng sử dụng trình quản lý xác thực owin để xác thực người dùng nhưng User.Identity.IsAuthenticated vẫn sai.Owin Authentication.SignIn không hoạt động
Startup.cs
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
Startup.Auth.cs
public partial class Startup
{
public static Func<UserManager<ApplicationUser>> UserManagerFactory { get; set; }
public Startup()
{
UserManagerFactory =() =>
{
var userManager = new UserManager<ApplicationUser>(new CustomUserStore());
return userManager;
};
}
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
LogoutPath = new PathString("/Account/LogOff"),
ExpireTimeSpan = TimeSpan.FromDays(7)
});
}
}
Một số phần của hành động xác thực:
private async Task SignInAsync(ApplicationUser user, bool isPersistent)
{
var authManager = return HttpContext.GetOwinContext().Authentication;
authManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
var identity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
authManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, identity);
}
Danh tính tạo thành công nhưng phương thức Đăng nhập không đăng nhập người dùng. Chuyện gì vậy?
Cookie có được gửi tới trình duyệt của bạn không? nó có được trình duyệt lưu giữ không? – trailmax
@trailmax, không, cookie không gửi tới trình duyệt. – Neshta