【问题标题】:How can I Set Authorization Url in Razor Pages如何在 Razor 页面中设置授权 URL
【发布时间】:2018-05-16 02:17:00
【问题描述】:

我的ConfigureServices如下:

    services.AddAuthentication(options =>
        {
            options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        })
        .AddCookie(o =>
        {
            o.LoginPath = "/User/Login";
    });

当需要授权的页面被调用时,它会被重定向到登录页面,其 URL 类似于 localhost:58731/User/Login?ReturnUrl=%2F

我怎样才能像这样设置这个网址:localhost:58731/Login/%2F

谢谢。

【问题讨论】:

    标签: authorization asp.net-core-2.0 razor-pages


    【解决方案1】:

    我不建议弄乱中间来修改该路径。尽管从 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?tabs=aspnetcore2x 之类的链接看来是可能的

    但是,您可以从您的User/Login 位置重定向到您想要的位置。如果您将User/Login 用于其他用途,您可以将o.LoginPath 更改为其他位置,然后再次使用类似这样的操作:

    public IActionResult Login(string ReturnUrl) => Redirect("~/Login/" + ReturnUrl);
    

    【讨论】:

      猜你喜欢
      • 2019-12-20
      • 1970-01-01
      • 2023-02-08
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 2014-03-18
      相关资源
      最近更新 更多