Model view controller Asp.NETMVC核心2-共享身份验证cookie
我有多个应用程序在localhost下运行,最终将部署在一个域名下,如Model view controller Asp.NETMVC核心2-共享身份验证cookie,model-view-controller,asp.net-core-2.0,cookie-authentication,Model View Controller,Asp.net Core 2.0,Cookie Authentication,我有多个应用程序在localhost下运行,最终将部署在一个域名下,如 申请如下: 当用户访问app1时,它会在内部使用安全应用程序将其登录。 我正在使用cookie身份验证。现在,当用户移动到app2时,我希望app2使用由app1创建的cookie,而不要求再次进行身份验证 Startup.cs: public void ConfigureServices(IServiceCollection services) { services.AddAuthentic
申请如下:
当用户访问app1时,它会在内部使用安全应用程序将其登录。 我正在使用cookie身份验证。现在,当用户移动到app2时,我希望app2使用由app1创建的cookie,而不要求再次进行身份验证 Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.AccessDeniedPath = new PathString("/LogUser/RestrictedAccess");
options.LoginPath = new PathString("/LogUser/Login");
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
options.SessionStore = new MemoryCacheTicketStore();
options.Cookie.Name = ".AspNet.SharedCookie";
options.Cookie.Path = "/";
options.ReturnUrlParameter = "OriginalUrl";
});
services.AddSession();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
主要有两种选择:
DataProtectionProvider
。使用DataProtectionProvider
对身份验证cookie(以及会话cookie等)进行加密。从某种意义上说,这与在每个应用程序的web.config中设置相同机器密钥的老式方法有些相似,只是ASP.NET Core不使用web.config,也不使用机器密钥进行加密。相反,您需要确保它使用持久化密钥存储,每个应用都可以访问和使用该密钥存储,并且禁用应用隔离。我建议深入调查一下,以确保你已经很好地掌握了你正在处理的事情以及每件事情的运作方式