指定一个网站的default page是很容易的事情。譬如IIS Management中,可以通过default page来指定,而默认的index.html, index.htm之类,则早已经被设置为默认了。
另外一种对ASP.NET网站行之有效的方法是,修改web.config。
譬如:
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="index.html" />
</files>
</defaultDocument>
</system.webServer>
但是,对于ASP.NET Core 1.0来说,它是Self Host的网站,所谓的deploy to IIS其实也只是安装一个proxy。具体参阅ASP.NET Core最新的文章
https://docs.asp.net/en/latest/publishing/iis.html
那,如果需要设置static file (通常是wwwroot文件夹)的文件为default page (这对纯的JavaScript 网站来说非常有必要。static files的使用方法,同样参阅ASP.NET Core的最新文档:https://docs.asp.net/en/latest/fundamentals/static-files.html),
针对最新的ASP.NET Core 1.0 RC2,在Startup.cs中的Configure方法中加入下列代码(替换index.html为任意其他文件):
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
//var physicalFileSystem = new PhysicalFileSystem(webPath);
var options = new FileServerOptions
{
EnableDefaultFiles = true,
//StaticFileSystem = physicalFileSystem
};
//options.StaticFileOptions.FileSystem = physicalFileSystem;
options.StaticFileOptions.ServeUnknownFileTypes = true;
options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" };
app.UseFileServer(options);
}
是为之记。
Alva Chien2016.5.25
本文介绍了如何在ASP.NET Core 1.0中配置默认首页,包括通过web.config及Startup.cs中的Configure方法来指定默认显示的文件。适用于静态文件为主的JavaScript网站。
1414

被折叠的 条评论
为什么被折叠?



