Jud*_*ngo 8 authentication asp.net-identity asp.net-core
我有一个.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永远不会被设置.
我错过了什么?
Jud*_*ngo 11
我解决了这个问题.它归结为HTTPS:看来signInManager.SignInAsync(...)设置了一个仅限HTTPS的cookie.我最初发布到非HTTPS站点进行测试.
一旦我发布到HTTPS站点,cookie就会重新开始工作.
它在本地工作的原因是我在本地运行HTTPS.
| 归档时间: |
|
| 查看次数: |
4398 次 |
| 最近记录: |