mvc routing generates iis 7.5 error forbidden

北战南征 提交于 2019-12-02 15:03:28

问题


I my WebApplication I have an ASPX WebForms Page here:

~/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.

But if I use the following code

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

and try

localhost/MySite/Test

IIS 7.5 says:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

Do I do something wrong in the last piece of code?

Thx in advance!


回答1:


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.

I got the error response 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. 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
  • I did not need to add UrlRoutingModule to the web.config under system.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.



回答2:


Reinstall .NET 4 x86 & x64 on IIS 7.5 and setup your web site .net version. I write simple commands by default x86.

Stopping 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

Reset command(for iis by defalt .net change to .net 4 version): 4)aspnet_regiis.exe -iru

Starting IIS: 5)iisreset /start




回答3:


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.



来源:https://stackoverflow.com/questions/10278463/mvc-routing-generates-iis-7-5-error-forbidden

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!