Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

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

But now I'm trying new Razor Pages approach, and now Members is folder and Index is Razor Page. How to set this page in folder as starting one?

I can add Index page in root directory and make redirect there, but I was looking for something cleaner.

like image 825
Makow Avatar asked Sep 08 '17 13:09

Makow


3 Answers

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.

like image 77
AllanB Avatar answered Nov 18 '22 21:11

AllanB


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

enter image description here

like image 20
Brad Patton Avatar answered Nov 18 '22 21:11

Brad Patton


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
like image 2
osynavets Avatar answered Nov 18 '22 22:11

osynavets