gpt4 book ai didi

c# - 我在哪里定义 aspnetcore 授权失败的 url?

转载 作者:行者123 更新时间:2023-12-04 09:14:00 24 4
gpt4 key购买 nike

所以我在我的 asp.net core 3+ 项目中有 aspnet identity razor 页面。
当我点击登录或注册默认值时,它会将我定向到以 Identity 开头的网址。例如

https://localhost:12345/Identity/Account/Login
所有到其他页面的导航、帐户管理等都工作正常,给我这个 Identity字首。
但是,我添加了一些 userRoles 并且正在使用 Authorize(Roles = "Admin")我的 MVC 上的属性 Admin Controller ,因此当我尝试在未登录的情况下访问此 Controller 上的索引页面时,它会尝试将我重定向到登录,并在查询字符串中使用 returnURL
但是 ,URL 缺少 Identity前缀并将我发送到:
https://localhost:12345/Account/Login?ReturnUrl=%2Fadmin
我在哪里改变这个?我不知道授权失败时的自动重定向在哪里?!

编辑:我认为它可能与声明端点的启动位有关:
        app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
不知道如何更改以创建默认登录路径

最佳答案

the URL is missing the Identity prefix and sends me to:

https://localhost:12345/Account/Login?ReturnUrl=%2Fadmin
如果您设置 登录路径 "/Account/Login"ConfigureServices Startup.cs 的方法如下,这会导致上述问题。
services.ConfigureApplicationCookie(options =>
{
//options here

options.LoginPath = "/Account/Login";

//...
});

关于c# - 我在哪里定义 aspnetcore 授权失败的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63303465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com