如何在 dotnet core web api 中设置起始页? [英] How to set start page in dotnet core web api?
本文介绍了如何在 dotnet core web api 中设置起始页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 dotnet core web api 构建一个 web 应用程序,但我不知道如何将 index.html 设置为起始页面,这可以使用 dotnet 框架 web api 轻松完成.我尝试使用 app.UseDefaultFiles();app.UseStaticFiles();
来解决这个问题,但是,它没有用.
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.
推荐答案
如果您使用静态文件作为默认页面,以下代码可以帮助您.
If you are using a static file as the default page, the following code can help you.
app.UseDefaultFiles(new DefaultFilesOptions { DefaultFileNames = new
List<string> { "index.html" } });
如果您使用的是 MVC 视图,只需添加路由角色.
If you are using the MVC view, just add the routing role.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
});
这篇关于如何在 dotnet core web api 中设置起始页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文