Application Root in MVC App?

asp.net-mvc, asp.net-mvc-routing, c#

Solution

You're looking for `HttpRuntime.AppDomainAppVirtualPath`.

Note that all of the `Url.*` helpers will do this for you.

Problem

I am having some problems with an MVC app that uses logic based off data driven URLs (for routing) if my application is deployed to anywhere else other than the domain root. I tried using various Request.Url properties to no avail. Let's say I deploy my app to `www.mydomain.com/myapp/` or even `www.mydomain.com/myapp/subapp/`. In these cases how can I get `/myapp/` and `/myapp/subapp/` respectively. Even if the user is on a totally different page such as `/myapp/Users/Recent/`? I need that so I can prefix all the data driven URLs so my app still works when not on the domain root. Thanks.

Original source