MVC路由生成IIS 7.5的错误禁止
我在我的WebApplication我有一个ASPX页面的WebForms这里:
I my WebApplication I have an ASPX WebForms Page here:
〜/ ASPWebforms / MyFolder中/ Default.aspx的
~/ASPWebforms/MyFolder/Default.aspx
如果我用这个code:
If I use this code:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapPageRoute(
"SomeRoute",
"Test/{reportname}",
"~/ASPWebforms/MyFolder/{reportname}.aspx"
);
然后在浏览器中输入:
and then enter this in the browser:
本地主机/ mysite的/测试/默认
localhost/MySite/Test/Default
我得到想要的结果:页面〜/ ASPWebforms / MyFolder中/ Default.aspx的显示
但是,如果我使用以下
code
But if I use the following code
routes.MapPageRoute(
"SomeRoute",
"Test/",
"~/ASPWebforms/MyFolder/Default.aspx"
);
和尝试
本地主机/ mysite的/测试
localhost/MySite/Test
IIS 7.5说道:
IIS 7.5 says:
HTTP错误403.14 - 禁止访问Web服务器配置为不清单
这个目录中的内容。
HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.
难道我做错事的最后一块code的?
Thx提前!
我有一些东西很多像这一点,并从阅读它周围似乎是它可以由几个不同的原因引起。在我来说,我有一个像这样的路线:
I had something a lot like this, and from reading around it seems like it could be caused by several different things. In my case I had a route like this:
routes.MapPageRoute("signin", "signin", "~/SignIn/SignIn.aspx")
所以布线路径是 /登入
,但也有 /登入
包含所谓的.aspx文件夹页。
So the route path is /signin
, but there is also a folder called /signin
containing the .aspx page.
我得到了错误的反应 HTTP错误403.14 - 禁止。 Web服务器配置为不列出此目录的内容
。
这时候我加了此行的路线配置是固定的:
This was fixed when I added this line to the route config:
routes.RouteExistingFiles = true;
在错误信息的真理在里面的谷物: /登入
是一个目录,Web服务器被配置为在它没有列出文件。看来,这个文件的路径花费precedence在路线,除非你配置它,否则。
The error message has a grain of truth in it: /signin
is a directory, and the web server is configured to not list files in it. It seems that this file path takes precedence over the route unless you configure it otherwise.
这是我尝试其他的事情:
Other things that I tried:
- 我并不需要使用不同的过载
的MapPageRoute
- 我也没必要
UrlRoutingModule
添加到Web.config下system.webServer |模块
。它的工作原理没有这种。 - 这作品,未经web.config中设置
<模块runAllManagedModulesForAllRequests =真正的>
我确实有其他原因,但如果我删除它,然后此修复仍然有效。 - 我没有在机器的
服务器管理器安装服务器功能HTTP重定向服务器|网络
对话,但再次取出后,这仍然有效
服务器|添加角色服务
- I did not need to use a different overload of
MapPageRoute
- I did not need to add
UrlRoutingModule
to the web.config undersystem.webServer|Modules
. It works without that. - It works without the web.config setting
<modules runAllManagedModulesForAllRequests="true">
I do have that for other reasons, but if I remove it then this fix still works. - I did install the server feature "Http Redirection" in the machine's
Server Manager|Web Server|Add Role Services
dialogue but after removing it again this still works.