MVC 路由不处理我的目录之一
我正在使用 ASP.NET MVC 和 IIS 7.0。我通过我的 Application_Error 覆盖很好地连接了 404 错误。
除了“控制器”、“模型”、“助手”等之外,我还有一个名为“文件”的目录,用于存储用户上传的文件。当我访问 http://www.mysite.com/files 时,没有得到“Not发现'我得到一个默认的 IIS 403 页面,该页面提供了太多信息(例如服务器的确切目录结构):
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
如果我尝试访问 http://www.mysite.com/controllers 或 http://www.mysite.com/controllers mysite.com/helpers,这两个都是带有代码文件的现有目录,我得到一个 404 页面,这就是我想要的。我不希望用户知道有关我的目录结构的任何信息。
为什么 MVC 不处理 /files 目录?
I'm using ASP.NET MVC with IIS 7.0. I've got 404 errors hooked up fine through my Application_Error override.
In addition to "Controllers", "Models", "Helpers" etc. I have a directory called 'Files' that I use to store user-uploaded files. When I go to http://www.mysite.com/files, instead of getting a 'Not Found' I get a default IIS 403 page that gives way too much information (e.g. exact directory structure of the server):
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
If I try to access http://www.mysite.com/controllers or http://www.mysite.com/helpers, which are both existing directories with code files, I get a 404 page, which is what I want. I don't want the user to know anything about my directory structure.
Why is MVC not handling the /files directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了这个。 Views 目录返回正确的“404”页面,但 Files 目录返回信息过多的 ASP.NET“无权限”页面的原因是:Views 目录中有一个 web.config 文件禁止显示文件。它具有以下代码片段来阻止 MVC 提供目录服务。
我刚刚在我的 Files 目录中添加了一个类似的 web.config 文件,而 MVC 现在的行为就像该目录不存在一样,这正是我想要的。
I figured this one out. The reason the Views directory was returning a proper '404' page but the Files directory was returning a too-much-information ASP.NET 'no permissions' page: there is a web.config file in the Views directory that prohibits showing files. It has the snippets below to stop MVC from serving the directory.
I just added a similar web.config file to my Files directory, and MVC now acts like the directory doesn't exist, which is exactly what I want.