ASP.NET Core 1.0: 指定Static File中的文件作为default page
指定一个网站的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 Chien
2016.5.25
是为之记。
Alva Chien

浙公网安备 33010602011771号