How to set start page in dotnet core web api?

后端 未结 9 698
广开言路
广开言路 2021-01-31 07:56

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 tri

9条回答
  •  我在风中等你
    2021-01-31 07:58

    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

提交回复
热议问题