How to change starting page, using Razor Pages in .NET Core 2?

后端 未结 4 1426
我寻月下人不归
我寻月下人不归 2020-12-20 13:37

I wanted to set my starting page to /Members/Index.

When I was using MVC, I configured it as following:

app.UseMvc(routes =>
            {
              


        
相关标签:
4条回答
  • 2020-12-20 13:48

    Add the following to your ConfigurationServices function in Startup.cs

     services.AddMvc().AddRazorPagesOptions(options =>
            {
                options.Conventions.AddPageRoute("/Members/Index", "");
            });
    

    If you have another index page you'll probably need to delete or rename it.

    0 讨论(0)
  • 2020-12-20 14:06

    For testing purposes you can change the start page by going to the Properties window for the web project and select the Debug tab. On the 'Launch browser' line enter the starting path

    0 讨论(0)
  • 2020-12-20 14:09

    I am using this way

    services.AddMvc()
        .AddRazorPagesOptions(options => 
        {
            options.AllowAreas = true;
            options.Conventions.AddAreaPageRoute("Home", "/Index", "");
        });
    

    My folder structure is:

     - Area
       |_ Home
          |_ Pages
             |_ Index.cshtml
       |_ //other areas
    
    0 讨论(0)
  • 2020-12-20 14:11

    Try following code at AppStart->RouteConfig.cs :

     routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}",
                defaults: new { controller = "Members", action = "Index"}
            );
    
    0 讨论(0)
提交回复
热议问题