Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set start page in dotnet core web api?

I try to build a web application with dotnet core web api,but i do not know how to set index.html as start page which can be done with dotnet framework web api easily. And i tried to use app.UseDefaultFiles();app.UseStaticFiles(); to solve this problem, however, it did not work.

like image 589
HongyanShen Avatar asked Nov 17 '16 04:11

HongyanShen


People also ask

How do I set the default login page in .NET Core?

From the new item window, select the HTML template, provide the name as “index. html” and then click on the Add button as shown in the below image. Once you add the HTML Page within the wwwroot folder, your project folder structure should be shown like below. Now, open the index.

What is startup file in .NET Core?

The Startup class ASP.NET Core apps use a Startup class, which is named Startup by convention. The Startup class: Optionally includes a ConfigureServices method to configure the app's services. A service is a reusable component that provides app functionality.


2 Answers

In Properties/launchSettings.json you can define the launchUrl

"profiles": {     "IIS Express": {         "commandName": "IISExpress",         "launchBrowser": true,         "launchUrl": "<your relative URL here>",         "environmentVariables": {             "ASPNETCORE_ENVIRONMENT": "Development"         }     } } 
like image 78
Floris Devreese Avatar answered Sep 25 '22 00:09

Floris Devreese


Step 1

app.UseDefaultFiles(); app.UseStaticFiles(); 

Step 2

Create a folder called "wwwroot". put a file called index.html

Step 3 (optional)

If you are the using the auto generated template, you can remove make the launchUrl blank like this

"launchUrl": "", 

Otherwise, you will have to manually keep going to the landing page every time during localhost running.

This is the correct way. But always use UseDefaultFiles() before UseStaticFiles Otherwise it won't work.

For reference: Core fundamentals of Static Files

like image 30
sebulbamalastare Avatar answered Sep 23 '22 00:09

sebulbamalastare