mvc routing generates iis 7.5 error forbidden

前端 未结 3 1061
执念已碎
执念已碎 2021-01-27 22:41

I my WebApplication I have an ASPX WebForms Page here:

~/ASPWebforms/MyFolder/Default.aspx

If I use this code:

    p         


        
3条回答
  •  -上瘾入骨i
    2021-01-27 23:27

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

提交回复
热议问题