Jav*_*ier 22 macos asp.net-mvc asp.net-core-mvc kestrel-http-server asp.net-core
我需要能够使用Kestrel Web服务器在默认url /下提供我的'index.html' .现在我只能使用完整路径(即/index.html)访问我的静态文件
同样,这在VisualStudio上完美运行,上下文是OSX与Kestrel
这是我的Startup.cs
public void ConfigureServices(DI.IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
我到目前为止的解决方案是在HomeController中进行重定向.但这很简单,我试图提供一个静态的html文件,老实说我不希望它由我的应用程序处理,如果可能直接从Kestrel服务.
hai*_*770 41
您需要启用DefaultFilesMiddleware使用UseDefaultFiles()并在调用之前将其放置UseStaticFiles():
app.UseDefaultFiles();
app.UseStaticFiles();
Run Code Online (Sandbox Code Playgroud)
如果不另行指定,则中间件DefaultFilesOptions默认使用默认值,这意味着将使用此默认文件名列表:
default.htm
default.html
index.htm
index.html
Run Code Online (Sandbox Code Playgroud)
请参阅MSDN
| 归档时间: |
|
| 查看次数: |
3424 次 |
| 最近记录: |