【发布时间】:2015-09-09 18:08:57
【问题描述】:
我的 wwwroot 静态文件没有被解析。
我知道要提供静态文件,我需要将它们放在 wwwroot 中:
favicon.ico 解析得很好,但 schema/v1-0.json 没有。我得到了一般信息:
您要查找的资源已被删除,有它的名字 已更改,或暂时不可用。
我在Startup 中连接了以下内容:
app.UseMiddleware<StaticFileMiddleware>(new StaticFileOptions());
app.UseStaticFiles();
我正在使用 DNX beta6。以上需要 beta5 包。我在网上找不到任何关于在 beta6 中提供静态文件的信息。我不确定这是否是问题的原因。
编辑:
根据 Sirwan 的回答,我添加了以下内容,但是 json 文件仍然不可用:
var options = new StaticFileOptions
{
ContentTypeProvider = new JsonContentTypeProvider(),
ServeUnknownFileTypes = true,
DefaultContentType = "application/json"
};
app.UseStaticFiles(options);
JsonContentTypeProvider 类:
public class JsonContentTypeProvider : FileExtensionContentTypeProvider
{
public JsonContentTypeProvider()
{
Mappings.Add(".json", "application/json");
}
}
浏览服务器时我什至可以看到文件:
【问题讨论】:
-
我的记忆在这里有点模糊,但我相信 IIS 或 ASP.NET MVC 按文件扩展名过滤允许的静态文件。例如,如果您在该位置添加一个 .png 文件,您可能可以正常访问它。您需要找到 web.config 或 ASP.NET 设置以指定允许的静态文件扩展名并将 .json 添加到其中
标签: azure visual-studio-2015 azure-web-app-service asp.net-core asp.net-core-mvc