简体   繁体   English

如何使Identity Login页面成为dotnetcore 2.1中的启动页面

[英]How to make the Identity Login Page the startup page in dotnetcore 2.1

I am creating a dotnetcore 2.1 application and have scaffolded the Identity Login page. 我正在创建一个dotnetcore 2.1应用程序,并且已搭建了Identity Login页面。 However, I don't know how to make the login page the startup page. 但是,我不知道如何使登录页面成为启动页面。 I know how to do it with Controllers and Actions but not with the scaffolded page. 我知道如何使用Controllers和Actions来做到这一点,但是不知道如何使用脚手架页面。 Please could someone enlighten me on how to do this ? 请有人启发我如何做到这一点?

As Brendan Green wrote in the comments you can add a restriction in your startup.cs file. 正如Brendan Green在评论中所写,您可以在startup.cs文件中添加限制。

This works in Asp.Net Core 2.0 and 2.1. 这适用于Asp.Net Core 2.0和2.1。

You can do this by use the following code in your startup.cs 您可以通过在startup.cs中使用以下代码来完成此操作

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc(o =>
    {
        var policy = new AuthorizationPolicyBuilder()
            .RequireAuthenticatedUser()
            .Build();
        o.Filters.Add(new AuthorizeFilter(policy));
    });
}

If you want to do this you need a user-store. 如果要执行此操作,则需要一个用户存储。 So you have to use the template with individual user accounts or you do with "new Scaffolded item" -> "identity" 因此,您必须对单个用户帐户使用模板,或者对“新的脚手架项目”->“身份”使用模板

I hope this help you? 希望对您有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM