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?

0

2 Answers 2

0

Use UrlHelper methods to do this work for you.

Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.