Search code examples
c#asp.netrestconfigvisual-studio-2019

ASP.NET and C#: where do you store the rest client url?


I have my rest client url hard-coded in my code-behind, but upon peer-reviewing my code, I was asked to move that url to the config file so that it can be changed for each environment.

Visual Studio 2019 now complains because my rest client url has an invalid = sign as token in the url itself, and it expects ; as token instead.

Has anyone ever come across this, and is it correct to move the rest client to the config file? In theory that should not change.

Can't share the full url, but the part that is highlighted as error is this: version=2.0&details=true.


Solution

  • If i will do that i will save in config file only base url like this

      "WebConfig": {
        "SmsCenterApi": "https://some_site.com/SendService"
      }
    
    

    and in code I can complete the link

    string url = WebConfigData.SmsCenterApi+"version=2.0&details=true";
    
    

    andafter that I can use url to make some request. For multi-environments web.config and appsettings is avesome. You just change base url for each env and that's it.