ASP.NET Core 设置默认起始页(如default.html)
测试页面foo.html
在startup.cs内使用middleware
代码如下:
1 defaultfilesoptions defaultfilesoptions = new defaultfilesoptions(); 2 defaultfilesoptions.defaultfilenames.clear(); 3 defaultfilesoptions.defaultfilenames.add("foo.html"); 4 app.usedefaultfiles(defaultfilesoptions); 5 app.usestaticfiles();
或者:
1 fileserveroptions fileserveroptions = new fileserveroptions(); 2 fileserveroptions.defaultfilesoptions.defaultfilenames.clear(); 3 fileserveroptions.defaultfilesoptions.defaultfilenames.add("foo.html"); 4 app.usefileserver(fileserveroptions);
运行结果:
static files in asp.net core
by default an asp.net core application will not serve static files; // 默认情况下asp.net core应用程序时不支持静态文件的。
the default directory for static files is wwwroot; //为静态文件提供存储的默认路径时wwwroot;
to serve static files usestaticfiles() middleware is required; //usestaticfiles() 。在使用静态文件时必须
to serve a default file usedefaultfiles() middleware is required; //userdefaultfiles() 。 在使用默认文件时必须
the following are the default files: //列举了4种默认文件名
index.htm
index.html
default.htm
default.html
usedefaultfiles() must be registered before usestaticfiles(); //usedefaultfiles()必须先于usestatcifiles()注册。
usefileserver combines the functionality of usestaticfiles,usedefaultfiles and usedirectorybrowser middleware. //usefileserver 集合了usestaticfiles,usedefaultfiles and usedirectorybrowser这些中间件的所有功能。
转自油管>static files in asp net core
下一篇: python随机数分布random测试