ASP.NET MVC routing not working in virtual directory

I have an asp.net mvc 2 application (using .net 4.0) that does not route correctly when placed 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 am trying to resolve http://mydomain.com/accounts/new . Where "accounts" is a virtual directory. If I put the application in the root directory of the IIS site, it will be redirected to http://mydomain.com/new , but if I put the application in the virtual directory I get 404 errors. I debugged and it does global.asax and configures routing when in vdir. Is there anything special I need to do for routing in a virtual directory?

FYI. I use vdir because it has wordpress in it.

Thank!

one more thing is that if I specify the default action in the default options, it will execute the default action / controller, but it will never match another.

+3
source share
2 answers

I get it. Wordpress (which I installed on the root website) set up some URL rewriting rules that prevented asp.net mvc from receiving any requests other than the root of the virtual directory. Everything related to this path was rewritten by index.php, which, of course, was not in my mvc application.

I deleted the rewrite rule and now everything works as expected.

+1

, :

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

Source: https://habr.com/ru/post/1755683/


All Articles