Ian Warburton
Ian Warburton

Reputation: 15676

Virtual directory overriding MVC route

I have a web app, A, that has a virtual directory that is also an app, B. I've tried to create an MVC route in A such that the URL appears to be in the virtual directory but is still handled by A and not B. However, it seems to be being ignored. Is there a way of making the MVC route take priority over the virtual directory?

Upvotes: 0

Views: 523

Answers (2)

JayC
JayC

Reputation: 7141

If you want App A to override App B, you're going to have to add some Url Rewriting configuration, not MVC routing logic, which, if you're using IIS7+ which, I believe, you should be set up in the web.config file for App A. IIS has to know which application to forward a request to; by the time MVC routing is invoked, the application has already been selected at that point (you cannot unselect B once the actual application is invoked * ). You also might be able to get away with setting up the url rewrite rules in App B to point to App A, but I'm not quite sure how that'd work.

Please note, what I'm saying about application invocation is very likely not strictly true. But to be honest, I don't know if I could give a completely accurate description of the lifecycle of a url rewritten request; I just hope I'm roughly approximating what happens in simplified terms. Just learn more about url rewriting in IIS and IIS7 request lifecycles visit the following links:

http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module http://msdn.microsoft.com/en-us/library/bb470252(v=vs.100).aspx

Upvotes: 1

Yogiraj
Yogiraj

Reputation: 1982

So you got two apps A & B. You say you tried to create MVC route but in which app? If you can explain a bit more what you trying to achieve, it will be easier to answer.

ASP.net routes (also available in web forms) can take any form you want. The one thing you must keep in mind that the route maps are greedy. So if most generic route is found first it is not going to check anything below no matter what. So the order should be most specific and last one should be most general.

Check this post http://yogiorchard.azurewebsites.net/archiving-items-and-a-routing-lesson

Hope this helps

Upvotes: 0

Related Questions