我有一个.NET Core 2 Web应用程序,我想使用ASP.NET Identity来验证我的用户.在.NET Core 1.x上,我的代码工作正常.
我迁移到.NET Core 2,并在Visual Studio中本地运行时进行身份验证.但是,当我部署到实时环境时,身份验证将停止工作:身份验证cookie未在生产环境中设置.
我的Startup.cs代码如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<AppUser, RavenDB.IdentityRole>()
.AddDefaultTokenProviders();
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseAuthentication();
}
Run Code Online (Sandbox Code Playgroud)
要登录,我的代码如下所示:
public async Task<ActionResult> SignIn(...)
{
var user = ...; // Load the User from the database.
await this.signInManager.SignInAsync(user, isPersistent: true);
...
}
Run Code Online (Sandbox Code Playgroud)
此代码在本地工作:设置了ASP.NET Identity auth cookie.但是,当我将此部署到Azure中的生产环境时,cookie永远不会被设置.
我错过了什么?