Reputation: 75
I have 1 website on IIS ("myWebsite") and another inside this one ("secondWebsite") as an application. Both are ASP.NET Mvc websites.
I have a method who works perfectly on the first one :
public static string AbsolutePath(this UrlHelper url, string path)
{
Uri requestUrl = url.RequestContext.HttpContext.Request.Url;
string absoluteAction = string.Format("{0}{1}", requestUrl.GetLeftPart(UriPartial.Authority), path);
return absoluteAction;
}
The result is : http://myWebsite.com/path
I have the same method in the second Website, the result is the same, that's logic, but I don't want it !
The result should be : myWebsite.com/secondWebsite/path. (miss the http:// cause of spam prevention ^^).
Is there a good way to do that ?
Thanks.
Upvotes: 1
Views: 559
Reputation: 34523
You could try using
string absoluteAction = string.Concat(Request.Url.Authority,
Request.ApplicationPath, path);
Upvotes: 1
Reputation: 6136
Can you not use Server.ResolveUrl("~/Path"); as that rebases from application root.
Upvotes: 0