【发布时间】:2018-01-24 09:33:53
【问题描述】:
我目前正在将我的 Web API 项目升级到 .NET Core 2.0
并且似乎 AddIdentity.Cookies 不再可用。
谁能指出我正确的方向?
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(Configuration);
services.AddMvc();
// Add framework services.
services.AddDbContext<ApplicationContext>(
options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<AuthContext>(options => options.UseSqlServer(Configuration.GetConnectionString("AuthConntection")));
services.AddIdentity<ApplicationUser, MyRole>(cfg =>
{
cfg.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents
{
OnRedirectToLogin = ctx =>
{
if (ctx.Request.Path.StartsWithSegments("/api"))
ctx.Response.StatusCode = (int)System.Net.HttpStatusCode.Unauthorized;
return Task.FromResult(0);
}
};
})
.AddUserStore<ApplicationUserStore>()
.AddDefaultTokenProviders()
.AddEntityFrameworkStores<AuthContext, Guid>();}
【问题讨论】:
标签: asp.net-core jwt asp.net-core-2.0