3

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?

2
  • Are they in the same asp.net application or not? If so, use the routes and route values. Required reading: asp.net/mvc/overview/controllers-and-routing. Commented Nov 24, 2014 at 9:46
  • They are different applications. Commented Nov 24, 2014 at 10:03

1 Answer 1

5

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

@string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"))
Sign up to request clarification or add additional context in comments.

2 Comments

I think the question is: how to get the application name, not how to format an url.
i think the point is to get the url with the base virtual path. anyway, the main part is Url.Content("~"), that returns the virtual path of the application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.