Asp.net core mvc Asp.Net MVC vNext身份登录路由更改不起作用

Asp.net core mvc Asp.Net MVC vNext身份登录路由更改不起作用,asp.net-core-mvc,Asp.net Core Mvc,我正在尝试设置登录、注销等的新路径 现在,当我使用app.UseIdentity时,它会自动路由到/Account/Login 当我尝试注释app.UseIdentity并添加 MapRoute( name: "Login", defaults: new { controller = "Security", action = "Login" }, template: "Login/{returnUrl?}") 及 它不做任何事情,除了路由到我的主页,并显示一个空白页,我

我正在尝试设置登录、注销等的新路径

现在,当我使用app.UseIdentity时,它会自动路由到/Account/Login

当我尝试注释app.UseIdentity并添加

MapRoute(
    name: "Login",
    defaults: new { controller = "Security", action = "Login" },
    template: "Login/{returnUrl?}")

它不做任何事情,除了路由到我的主页,并显示一个空白页,我认为,因为它是未经授权的


正确的方法是什么?

刚刚通过查看Asp.Net源代码找到了答案:


请显示Startup.cs文件。我已经编辑过以显示答案
//app.UseIdentity();

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookies",
    LoginPath = new PathString("/Login"),
    LogoutPath = new PathString("/Logout")
});
public static class MyIdentityExtensions
{
    public static IApplicationBuilder UseMyIdentity(this IApplicationBuilder app)
    {
        if (app == null) {
            throw new ArgumentNullException(nameof(app));
        }

        var options = app.ApplicationServices.GetRequiredService<IOptions<IdentityOptions>>().Value;

        app.UseCookieAuthentication(options.Cookies.ExternalCookie);
        app.UseCookieAuthentication(options.Cookies.TwoFactorRememberMeCookie);
        app.UseCookieAuthentication(options.Cookies.TwoFactorUserIdCookie);

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            LoginPath = new PathString("/Login"), // REPLACED THIS
            LogoutPath = new PathString("/Logout"), // ADDED THIS
            AuthenticationScheme = options.Cookies.ApplicationCookieAuthenticationScheme,
            AutomaticAuthenticate = true,
            AutomaticChallenge = true,
            Events = new CookieAuthenticationEvents
            {
                OnValidatePrincipal = SecurityStampValidator.ValidatePrincipalAsync
            }
        });

        return app;
    }
}
app.UseMyIdentity()