views:

122

answers:

2

I have an asp.net mvc 2 app (using .net 4.0) that isn't routing correctly when hosted in a virtual directory. I have the following simple routing rule:

        routes.MapRoute(
            "Default", // Route name
            "{action}", // URL with parameters
            new { controller = "accounts" } // Parameter defaults
        );

I'm trying to resolve http://mydomain.com/accounts/new. Where "accounts" is a virtual directory. If I put the app in the root of an IIS website it routes fine for http://mydomain.com/new, but if I put the app in a virtual directory I get 404 errors. I've debugged and it is executing global.asax and configuring routing when in the vdir. Is there something special I need to do for routing in a virtual directory?

FYI. I'm using a vdir because the root has wordpress in it.

Thanks!

one more thing is that if I specify a default action in parameter defaults, it will execute the default action/controller, but it never matches anything else.

A: 

does it work if you change it to:

routes.MapRoute( 
    "Default", // Route name 
    "accounts/{action}", // URL with parameters (BUT WITH ACCOUNTS PREFIX)
    new { controller = "accounts" } // Parameter defaults 
); 
BritishDeveloper
no that doesn't work either.
Matt Dotson
A: 

I figured it out. Wordpress (which I had installed at the website root) had configured some URL rewrite rules which were preventing asp.net mvc receiving any requests other than the virtual directory root. Anything with a path beyond that was being rewritten to index.php which of course didn't exist in my mvc app.

I removed the rewrite rule, and now everything works as expected.

Matt Dotson