如何在 ASP.NET MVC 中使用文件扩展名的路由,该路由将被请求过滤阻止
我有一个基本上如下所示的路由:
Foo/{id}/Files/{*path}
我希望它与 URL 匹配,例如:
http://mysite/Foo/Bar/Files/Baz.cs
但是,我收到 HTTP 404.7 错误,显示“请求过滤模块配置为拒绝文件扩展名”。我可以通过修改 web.config 从请求过滤中删除文件扩展名,但我不希望我的源代码可见。我应该如何设置这个?
I have a route that basically looks like this:
Foo/{id}/Files/{*path}
I want it to match a URL such as:
http://mysite/Foo/Bar/Files/Baz.cs
However, I get an HTTP 404.7 error that says "The request filtering module is configured to deny the file extension." I can remove the file extension from request filtering by modifying web.config, but I don't want my source code to be viewable. How should I set this up?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使其正常工作的唯一方法是通过 ASP.NET 4.0 中的relaxedUrlToFileSystemMapping 设置。您可以在此处阅读更多信息:
The only way you might have possibility to get it working is through relaxedUrlToFileSystemMapping setting in ASP.NET 4.0. You can read more here:
如果文件的路径与您想要的 url 不匹配,您可以执行以下操作:
将保存源文件的文件夹标记为 web.config 中的每个人都拒绝(例如 /源代码目录)
在请求过滤模块中允许.cs扩展名
If the paths to the files don't match with the urls you want to have than you can do the following:
mark the folder where you keep your source files as denied for everyone in the web.config (example for the /SourceCode dir)
allow the .cs extension in the request filtering module