c# – 指定asp.net核心静态文件夹的默认文件名
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 指定asp.net核心静态文件夹的默认文件名,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1321字,纯文字阅读大概需要2分钟。
内容图文
![c# – 指定asp.net核心静态文件夹的默认文件名](/upload/InfoBanner/zyjiaocheng/811/d1c2261f23dd420cb446cf37dbcaff50.jpg)
我目前有一个生成的index.html,js和其他静态文件存在于一个文件夹中,我将该文件夹标记为静态文件夹(通过在Startup.cs中的Configure方法中添加以下内容:
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new Path.Combine(env.ContentRootPath, @"../build")),
RequestPath = new PathString("/app/")
});
有没有办法将index.html设置为此* / app路由的默认响应?因为现在localhost:5000 / app /返回404而localhost:5000 / app / index.html返回index.html.
编辑:我错过了提到我确实尝试使用docs中提到的app.UseDefaultFiles(),但它对我不起作用.服务器仍然返回404
解决方法:
docs中的一条评论澄清了这一点:
Kieren_Johnstone
Featured May 22, 2017The section, “Serving a default document” misses some vital
information. If you configure your UseStaticFiles to work off a
non-root RequestPath, you need to pass the same FileProvider and
RequestPath into both UseDefaultFiles and UseStaticFiles, it seems.
You can’t always just call it as stated in the section.
这意味着,您应该编写类似这样的内容,以使您指定的文件夹能够提供默认页面:
app.UseDefaultFiles(new DefaultFilesOptions()
{
FileProvider = new Path.Combine(env.ContentRootPath, @"../build")),
RequestPath = new PathString("/app/")
});
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new Path.Combine(env.ContentRootPath, @"../build")),
RequestPath = new PathString("/app/")
});
内容总结
以上是互联网集市为您收集整理的c# – 指定asp.net核心静态文件夹的默认文件名全部内容,希望文章能够帮你解决c# – 指定asp.net核心静态文件夹的默认文件名所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。