0

I am trying to create an absolute path url so i can send to users via json:

So far i did it this way:

First, I created a static class with a static string:

public static class baseUrl
{
    public static string getBaseUrl(){
        return "http://myurl";
    }
}

Second, on the model, I created a custom column that concatenates the string and creates a new field with the full absolute path:

public string Image
   {
    get
    {
        return baseUrl.getBaseUrl()+"/images/" +Id+ "/content/" + Img;
    }
} 

My question is if there is a way to get the base url instead of using a static string, so it will be automatically changed on different environments, or if there is a better way to achieve the desired result?

Steve
  • 6,334
  • 4
  • 39
  • 67
sm13294
  • 563
  • 7
  • 23

2 Answers2

0

Use UrlHelper methods to do this work for you.

Cj S.
  • 1,173
  • 8
  • 13
0

debug request object , you will find base url of your current application in some property of this object.

var request = HttpContext.Current.Request

for more help visit this link

How can I get my webapp's base URL in ASP.NET MVC?

Community
  • 1
  • 1
Ankush Jain
  • 5,654
  • 4
  • 32
  • 57