dotnet/aspnetcore

Option to look for default files at the root of wwwroot path only, not at subpath

Open

#2,455 创建于 2018年1月1日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)C# (10,653 fork)batch import
affected-fewarea-middlewareenhancementfeature-static-fileshelp wantedseverity-minor

仓库指标

Star
 (37,933 star)
PR 合并指标
 (平均合并 16天 9小时) (30 天内合并 258 个 PR)

描述

From @NickAb on Sunday, February 28, 2016 6:26:46 AM

DefaultFiles middleware allows routing to default files at request subpath if no file was found, but for angular or other single page apps we would need to always route to /wwwroot/index.html for any subpath, i.e.:

  • http://localhost:5000/ -> wwwroot/index.html
  • http://localhost:5000/some-sub-path -> wwwroot/index.html

Currently we have to write custom middleware to handle this case (see stackoverflow for example). But it seems that adding option to DefaultFiles to route to wwwroot will be a good solution for such a common case.

https://github.com/aspnet/StaticFiles/blob/dev/src/Microsoft.AspNetCore.StaticFiles/DefaultFilesMiddleware.cs#L67

Copied from original issue: aspnet/StaticFiles#115

贡献者指南