Tom741
Tom741

Reputation: 75

ASP.NET Mvc absolute url with an application inside a website

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

Answers (2)

Alexander Prokofyev
Alexander Prokofyev

Reputation: 34523

You could try using

string absoluteAction = string.Concat(Request.Url.Authority, 
    Request.ApplicationPath, path);

Upvotes: 1

Paul Hadfield
Paul Hadfield

Reputation: 6136

Can you not use Server.ResolveUrl("~/Path"); as that rebases from application root.

Upvotes: 0

Related Questions