Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 410
Zizzipupp Avatar asked Dec 17 '22 15:12

Zizzipupp


2 Answers

I found the answer. The problem is in the & symbol itself. Once converted to &, the errors Visual Studio was highlighting were gone and my solution worked again.

like image 153
Zizzipupp Avatar answered Dec 21 '22 23:12

Zizzipupp


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 = WebConficData.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.

like image 29
BASKA Avatar answered Dec 22 '22 00:12

BASKA