我在 localhost 下运行了多个应用程序,最终将部署在一个域名下,例如https://myapp.com/
应用程序将如下所示:
https://myapp.com/security
https://myapp.com/app1
https://myapp.com/app2
当用户访问 app1 时,它会在内部使用安全应用程序登录他。我正在使用 cookie 身份验证。现在,当用户移动到 app2 时,我希望 app2 使用 app1 创建的 cookie 并且不再要求进行身份验证。
启动.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?}");
});
}