OK most of us develop and test the Asp.NET Web Applications in our localhost before publishing them to the production server. But to me, localhost is a pain sometimes since I cannot get the absolute path properly. Because lets say my app is located in http://localhost/MyApp/ I cannot properly get the host. I can get it with a couple of code but I like to make it more generic so whenever some other developer puts the same application in another location such as http://localhost/TheirApp, then it should work fine.
Sample Problem:
Whenever I use absolute path like this /aboutus.aspx, it causes this http://localhost/aboutus.aspx and omits MyApp. If I use relative path, then it becomes http://localhost/MyApp/IamHere.aspx/aboutus.aspx which is rather disturbing.
So if Request.Url.Authority or Request.Url.Host would return http://localhost/MyApp then we could append our url using these and find a nice solution.
An Alternative Solution:
I could do this:
if(Request.Url.Host.StartsWith("localhost"))
{
string[] segments = Request.Url.AbsolutePath.Split("/");
var localHost = Request.Url.Authority + "/" + segments[0];
}
then I can use localHost variable and append my path to it.
But I like to learn how you guys are dealing with such problem?
Thanks,