Tolga Evcimen
Tolga Evcimen

Reputation: 7352

How to get the url with application name in .net mvc?

Is there any way that I get the host address with the Application Name in IIS of my websites? To make my question clear here are few examples of what I want:

http://example.com/constructionSite/myController/myAction?blah=blahh
http://example.com/tr.Implementation/myOtherController/myAction?blah=blahh
http://example.com/anotherApplication/myController/myAction?blah=blahh
http://example.com/myOtherOtherController/myAction?blah=blahh

In my IIS I have applications like those above constructionSite, tr.Implementation, anotherApplication, myController. I need to get the urls with the application names on IIS, in other words up until the myController/...... And myController will not allways be the same controller, so I cannot use .IndexOf() method.

I tried playing with System.Web.HttpContext.Current.Request.Url.AbsoluteUri, System.Web.HttpContext.Current.Request.Url.AbsolutePath these paths, but it doesn't satisfy me.

What should be the appropriate approach to get the url with application name?

Upvotes: 3

Views: 3716

Answers (1)

Massimo Franciosa
Massimo Franciosa

Reputation: 554

you can try using Url.Content("~")

@string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"))

Upvotes: 5

Related Questions