Absolute URL from _Layout.cshtml

1

I am developing a page in which I upload images and PDFs, the problem is that I want to put for example when I select a PDF to see it, the url comes up with the full path to say it www.ejemplo.com/home/pdf/ejemplo.pdf , until now the images they are saved with the following path ../Home/Imagenes/ or ../Home/PDF/ , but when talking to some colleagues when the page is on the server it must show the full path ie the protocol, the server and the route. The truth is that I have no idea how to do it, I was investigating but I did not find something that could help me.

    
asked by Amairani Fernanda 26.06.2017 в 16:49
source

1 answer

1

Extracted from: link

You can do a Helper class that you reuse throughout the system:

public static string ResolveServerUrl(string serverUrl, bool forceHttps)
{
    if (serverUrl.IndexOf("://") > -1)
        return serverUrl;

    string nuevaUrl = serverUrl;
    Uri originalUri = System.Web.HttpContext.Current.Request.Url;
    nuevaUrl = (forceHttps ? "https" : originalUri.Scheme) +
        "://" + originalUri.Authority + nuevaUrl;
    return nuevaUrl;
} 

You use it this way:

ResolveServerUrl(VirtualPathUtility.ToAbsolute("~/images/image1.gif"),false))

The result:

http://www.yourdomainname.com/images/image1.gif
  

"I was investigating but I did not find something that could help me."

To find this example, these were the words in the search engine of link You have to be ecological: D We are reforesting our planet in our day to day!

  

"aspnet mvc get full url"

    
answered by 26.06.2017 в 18:50