c# - 将默认身份登录路由更改为自定义 asp.net 核心
问题描述
我在这方面看到了很多其他线程,但没有人说过是否可以将 Identity/Account/Login 的端点路由重命名为 /Home 之类的名称。是否可以在不从 Startup 类中删除 AddDefaultIdentity 的情况下执行此操作?
解决方案
有可能的,
在 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;
});
推荐阅读
- macos - 如何将 Rust 应用程序从 macOS x86 交叉编译到 macOS Silicon?
- javascript - 当我使用 PrivateRoute 时,我总是在重新加载页面时进入一次登录页面
- angularjs - 使用 stateProvider 进行路由时,如何在 AngularJS SPA 上获取 URL 参数
- node.js - npm serial-port 获取输出以响应组件
- python - 设置蟒蛇
- spring-boot - Spring Boot SecurityContextHolder.getContext().getAuthentication() 在基本身份验证上返回 null
- apache - 如何将 HTACCESS 更改重定向到现在允许子目录 URL?
- javascript - 在 mongodb 中存储/更新深度嵌套的对象数组
- elasticsearch - 为什么不同设备的最大指标结果相同?
- elasticsearch - ElasticSearch - 嵌套数组中的唯一计数