how can I set a specific page as a default page in .net core 2 using visual studio code


Hi, I'm using visual studio code to develop a web site using asp.net core 2. when I debug the project the default page is set as : https://localhost:xxxx

I want to set my page : "Account/Login" as my website's default page .

means when I debug the project the first screen should appear will this : https://localhost:xxxx/Account/Login

how can I do that?

Thanks 


Asked by:- LuneAgile
0
: 5369 At:- 12/6/2018 12:25:12 PM
ASP.NET asp.net-core set-starting-page-in-net-core







2 Answers
profileImage Answered by:- vikas_jk

Within that AddRazorPagesOptions() method, we can set things like route conventions and the root directory for pages. It turns out that, to set a default route for a page, you execute this call

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().AddRazorPagesOptions(options =>
    {
        options.Conventions.AddPageRoute("/Account/Login", "");
    });
}

Check the Detailed post here https://exceptionnotfound.net/setting-a-custom-default-page-in-asp-net-core-razor-pages/

OR set default route in Startup.cs (https://andrewlock.net/exploring-program-and-startup-in-asp-net-core-2-preview1-2/)

   public IConfigurationRoot Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        //some code here
         
        //add routing here
        app.UseMvc(routes =>
        {
            //default route
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }

In the above code we are adding a default route.

1
At:- 12/6/2018 4:21:08 PM


profileImage Answered by:- LuneAgile

Thanks so much  vikas_jk.

0
At:- 12/6/2018 7:28:36 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use