在ASP.NET 5提供静态文件MVC 6
我的wwwroot的静态文件没有被解决。
My wwwroot static files aren't being resolved.
据我了解,为静态文件,我需要把它们的wwwroot:
I understand that to serve static files, I need to put them in wwwroot:
的favicon.ico
解决得很好,但模式/ v1-0.json
没有。我得到的一般消息:
favicon.ico
resolves just fine, but schema/v1-0.json
does not. I get the generic message:
您正在查找的资源已被删除,有其名
更改,或者暂时不可用。
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
我有以下的启动
接线
app.UseMiddleware<StaticFileMiddleware>(new StaticFileOptions());
app.UseStaticFiles();
我使用DNX beta6。以上要求beta5的包。我找不到任何在线关于beta6提供静态文件。我不知道这可能是问题的原因。
I am using DNX beta6. The above require beta5 packages. I cannot find anything online regarding serving static files in beta6. I am not sure if this could be the cause of the problem.
编辑:
根据Sirwan的回答,我已经添加了以下,但JSON文件仍不可用:
As per Sirwan's answer, I have added the following, but the json file is still not available:
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");
}
}
我甚至可以看到文件浏览服务器时:
I can even see the file when browsing the server:
如果您正在使用IIS,请确保您添加正确的MIME类型映射,如果你没有一个包罗万象的托管处理程序。即使你不这样做的需求的web.config中为您的网站工作,IIS将仍然使用为您的网站。
If you're using IIS, make sure you've added the correct mime-type mappings if you don't have a catch-all managed handler. Even though you don't need web.config for your website to work, IIS will still use that for your website.
有人纠正我,如果我错了,但我相信,如果您还没有配置IIS以使用托管处理程序为静态文件还是会默认为 StaticFileModule
并呼吁 app.UseStaticFiles
实际上并没有做任何事情。如果您运行使用DNX,但是,那么 app.UseStaticFiles
它被使用。
Someone correct me if I'm wrong, but I believe that if you have not configured IIS to use a managed handler to serve static files it will still default to StaticFileModule
and calling app.UseStaticFiles
doesn't actually do anything. If you run it using dnx, however, then app.UseStaticFiles
gets used.
只是一个侧面说明,你应该还,如果您还没有升级到同β7。
Just a side note, you should probably also upgrade to beta7 if you haven't already.