首页 > 解决方案 > 将默认身份登录路由更改为自定义 asp.net 核心

问题描述

我在这方面看到了很多其他线程,但没有人说过是否可以将 Identity/Account/Login 的端点路由重命名为 /Home 之类的名称。是否可以在不从 Startup 类中删除 AddDefaultIdentity 的情况下执行此操作?

标签: c#asp.netasp.net-coreroutesasp.net-identity

解决方案


有可能的,

在 Startup.ConfigureServices 中配置应用程序的 cookie。调用 AddIdentity 或 AddDefaultIdentity 后必须调用 ConfigureApplicationCookie。

services.ConfigureApplicationCookie(options =>
{
    options.AccessDeniedPath = "/Identity/Account/AccessDenied";
    options.Cookie.Name = "YourAppCookieName";
    options.Cookie.HttpOnly = true;
    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
    options.LoginPath = "/Identity/Account/Login";
    // ReturnUrlParameter requires 
    //using Microsoft.AspNetCore.Authentication.Cookies;
    options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
    options.SlidingExpiration = true;
});


推荐阅读