简体   繁体   中英

Default page of MVC application not found when using .mvc.aspx in Route

I'm trying to use ASP.NET MVC with older versions of IIS that have trouble with MVC's default routing. I found a suggestion to add .mvc.aspx to my routes. So instead of this:

    routes.MapRoute( _
        "Default", _
        "{controller}/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", 
                  .id = UrlParameter.Optional} _
    )

I now use this:

    routes.MapRoute( _
        "Default", _
        "{controller}.mvc.aspx/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", 
    )

This works at getting MVC to work on older versions of IIS. However, when I navigate to http://win2k3machine/MyMVCApplication/ , I get "Directory Listing Denied" message. Similarly, when I use Casini (Visual Studio's development web server) and navigate to http://localhost:2019 , I get a "Server Error in '/' Application." message.

What do I need to change in IIS and/or my MVC application to get the default page to work correctly?

NOTE: I tried adding RouteTable.Routes.RouteExistingFiles = True per this answer , but that didn't seem to fix the problem.

You need to add Wildcard mapping in IIS. Refer to this article for more details:

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx

I had difficulty getting Wildcard mapping to work in IIS 6. However, adding a Default.aspx page with the following code fixed the issue:

VB.NET:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
  Handles Me.Load
    HttpContext.Current.RewritePath(Request.ApplicationPath, False)
    Dim httpHandler As IHttpHandler = New MvcHttpHandler()
    httpHandler.ProcessRequest(HttpContext.Current)
End Sub

C#:

public void Page_Load(object sender, System.EventArgs e) 
{ 
    HttpContext.Current.RewritePath(Request.ApplicationPath, false); 
    IHttpHandler httpHandler = new MvcHttpHandler(); 
    httpHandler.ProcessRequest(HttpContext.Current); 
} 

Olders versions of IIS want to see a Default.aspx page, so this page rewrites the path to work correctly. If you get the Wildcard mapping to work in IIS, you don't need this page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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