简体   繁体   English

mvc 路由生成 iis 7.5 错误禁止

[英]mvc routing generates iis 7.5 error forbidden

I my WebApplication I have an ASPX WebForms Page here:我的 WebApplication 我在这里有一个 ASPX WebForms 页面:

~/ASPWebforms/MyFolder/Default.aspx ~/ASPWebforms/MyFolder/Default.aspx

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:然后在浏览器中输入:

localhost/MySite/Test/Default本地主机/我的站点/测试/默认

I get the desired the result: The page ~/ASPWebforms/MyFolder/Default.aspx is displayed.我得到了想要的结果:显示页面 ~/ASPWebforms/MyFolder/Default.aspx。

But if I use the following code但是如果我使用下面的代码

routes.MapPageRoute(
                    "SomeRoute",
                    "Test/",
                    "~/ASPWebforms/MyFolder/Default.aspx"
       );

and try并尝试

localhost/MySite/Test本地主机/我的站点/测试

IIS 7.5 says: IIS 7.5 说:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory. HTTP 错误 403.14 - Forbidden Web 服务器配置为不列出此目录的内容。

Do I do something wrong in the last piece of code?我在最后一段代码中做错了什么吗?

Thx in advance!提前谢谢!

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")

So the route path is /signin , but there is also a folder called /signin containing the .aspx page.所以路由路径是/signin ,但还有一个名为/signin的文件夹,其中包含 .aspx 页面。

I got the error response HTTP Error 403.14 - Forbidden. The Web server is configured to not list the contents of this directory我收到错误响应HTTP Error 403.14 - Forbidden. The Web server is configured to not list the contents of this directory HTTP Error 403.14 - Forbidden. The Web server is configured to not list the contents of this directory . HTTP Error 403.14 - Forbidden. The Web server is configured to not list the contents of this directory

This was fixed when I added this line to the route config:当我将此行添加到路由配置时,此问题已修复:

routes.RouteExistingFiles = true;

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.错误消息有一定道理: /signin是一个目录,Web 服务器配置为不列出其中的文件。 It seems that this file path takes precedence over the route unless you configure it otherwise.除非您以其他方式配置,否则此文件路径似乎优先于路由。

Other things that I tried:我尝试过的其他事情:

  • I did not need to use a different overload of MapPageRoute我不需要使用不同的MapPageRoute重载
  • I did not need to add UrlRoutingModule to the web.config under system.webServer|Modules .我不需要将UrlRoutingModule添加到system.webServer|Modules下的 web.config 中。 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.它在没有 web.config 设置的情况下工作<modules runAllManagedModulesForAllRequests="true">由于其他原因我确实有这个,但如果我删除它,那么这个修复仍然有效。
  • 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.我确实在机器的“ Server Manager|Web Server|Add Role Services对话框中安装了服务器功能“Http 重定向”,但再次将其删除后,这仍然有效。

Reinstall .NET 4 x86 & x64 on IIS 7.5 and setup your web site .net version.在 IIS 7.5 上重新安装 .NET 4 x86 & x64 并设置您的网站 .net 版本。 I write simple commands by default x86.默认情况下,我编写简单的命令 x86。

Stopping IIS: 1)iisreset /stop停止 IIS: 1) iisreset /stop

Stup command(for iis by default .net stup): 2) cd %windir%\\Microsoft.NET\\Framework\\v4.0.30319 3)aspnet_regiis.exe -i Stup 命令(默认为 iis .net stup):2) cd %windir%\\Microsoft.NET\\Framework\\v4.0.30319 3)aspnet_regiis.exe -i

Reset command(for iis by defalt .net change to .net 4 version): 4)aspnet_regiis.exe -iru重置命令(对于 iis,通过 defalt .net 更改为 .net 4 版本):4)aspnet_regiis.exe -iru

Starting IIS: 5)iisreset /start启动 IIS: 5)iisreset /start

Try setting up the route using one of the overloads that sets default values like so:尝试使用设置默认值的重载之一来设置路由,如下所示:

            routes.MapPageRoute(
                    "SomeRoute",
                    "Test/{reportname}",
                    "~/ASPWebforms/MyFolder/{reportname}.aspx",
                    false,
                    new RouteValueDictionary(new {reportname = "Default"})
            );

Not massively confident it will sort your problem but with it working with your original example it could well do.不是很有信心它会解决您的问题,但与您的原始示例一起使用它可以很好地完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM