0
我目前正在升級我的Web API項目.NET核2.0 ,似乎AddIdentity.Cookies
不再可用。Asp.net核2.0基本JWT缺少ApplicationCookie
任何人都可以指向正確的方向嗎?
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>();}