c# - 如何将登录页面设置为 ASP .NET Core 2.1 中的默认路由?

标签 c# asp.net-identity asp.net-mvc-routing razor-pages asp.net-core-2.1

我是 ASP .NET Core 2.1 的初学者,正在从事使用 ASP .NET Core 2.1 和个人身份验证的项目。我想让我的登录页面成为我的默认路由,而不是 Home/Index:

            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

任何帮助我如何将它更改为 ASP .NET Core 2.1,因为登录现在用作 Razor 页面而不是 MVC 操作 View 。

最佳答案

ConfigureServices 方法中使用它。

services.AddMvc().AddRazorPagesOptions(options=> {
   options.Conventions.AddAreaPageRoute("Identity", "/Account/Login",""); 
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

然后在Configure方法

 app.UseMvc(routes =>
        {
            routes.MapRoute(
               name: "default",
               template: "{controller=Home}/{action=Index}/{id?}");

        });

关于c# - 如何将登录页面设置为 ASP .NET Core 2.1 中的默认路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51506419/

相关文章:

c# - C++ DLL 在运行时抛出异常

c# - 附加到 VARCHAR 的大小度量是什么?

c# - 我如何解决 Cannot create a DbSet for 'CUserMasterLocal' because this type is not included in the model for the context

c# - ASP.Net 标识 : Difference between UseOAuthBearerTokens and UseCookieAuthentication?

asp.net-web-api - 身份验证和授权作为中央微服务 ASP.NET

asp.net-mvc - MVC 4 捕获所有路线从未到达

asp.net-mvc - 使用自定义段变量设置 ASP.Net MVC 4 路由

c# - 替换 .Net Standard 2.0 中的 string.Contains(string, StringComparison)

c# - appveyor 中的 xunit.console 在寻找 xunit.dll 时失败

asp.net-mvc - ASP.NET MVC - 缩短网址