I am using a method like this in order to get the URL path of my application:
string strPathAndQuery = HttpContext.Request.Url.PathAndQuery;
string strUrl = HttpContext.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");
This is supposed to path to the current URL.
The problem is, my live server runs the application as an application (folder) inside an IIS server. So when testing a I get a URL like:
http://localhost/Survey/Create
And live I get:
http://testurl.com/Survey/Create
When what I need for the live server is:
http://testurl.com/SurveyApp/Survey/Create
With SurveyApp being the folder that stores the application in IIS. Is there a way that I can get the URL of where the controllers are located, regardless of physical location?
MVC has methods for this reason, such as Url.Content. These will resolve the currect url when you use an app dir relative path like “~/Survey/Query”. You would also use methods like Html.ActionLink or Url.Action to get url’s to specific action methods. These will adjust to your correct path.
Can you be more specific about WHY you are trying to get the path?