views:

35

answers:

3

Hello everyone,

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.

A: 

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

Paul Hadfield
I didn't know this but one.Works for a view but I want to use this for the css files :/<%:ResolveUrl("Content/styles_1.css")%> give me Views/Shared/Content/styles_1.css ^^. And it doesn't qive me absolute url :/
Tom741
Inside a view, using <%=ResolveUrl("~/styles/main.css")%> will reference the styles folder within the application in question and not rebase from the root of the server. If you're just trying to reference css files and js files from within your view this should be all you need to do - it's tried and tested to work with sites that are either off the root of the IIS website, or nested within applications/virtual directories. If that is not what you are doing, can you please provide more context for the problem you are trying to solve. Thanks.
Paul Hadfield
A: 

You could try using

string absoluteAction = string.Concat(Request.Url.Authority, 
    Request.ApplicationPath, path);
Alexander Prokofyev
A: 

Alexander solution works perfect for me. Thank you everyone.

Tom741
You would better check the best answer which gives some reputation points to you and to the answerer. :)
Alexander Prokofyev