0

Tried with the IP, but I don't know if it will change. Either if the host name can change as well, i don't know. It needs to be something static. Using nslookup site.com in cmd, it shows one IP xxxx. But inside C# App the following code below display YYYY

  Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString()

If I guess, one is the outbound IP, and the other the inbound one.

It's necessary for a database connection between test and production.

What can I do to achieve this objective?

  • Try using the slot name, see https://stackoverflow.com/questions/50147803/getting-the-azure-app-service-slot-name-on-startup – Peter Bons Nov 25 '20 at 12:48
  • Why don't you pass the database connection string in when you deploy to the environment? – mason Nov 25 '20 at 13:48
  • @mason it needs to be automatic without more than one Web.config file(No duplicated config). – JeffBusterCase Nov 25 '20 at 18:14
  • What do you mean by "automatic"? And why do you think my suggestion involves more than one config file? – mason Nov 25 '20 at 18:35
  • What is " pass the database connection string" and how to get from C#? – JeffBusterCase Nov 25 '20 at 18:45
  • I may not be fully understanding your question, but why not use the Azure App Service's configuration? You can have different configurations—including different connection strings—per App Service. As @PeterBons, this can also be configured in conjunction with deployment slots. You can even have a configuration variable that you set to e.g. `debug` or `release` to detect the environment via your code, then access that as a configuration variable (the same way you would if it were in e.g. `AppSettings`). – Jeremy Caney Nov 27 '20 at 21:01
  • Does the response below help? – Harshita Singh Dec 03 '20 at 05:13
  • No, cause I do not want a alterable Web.config. But mason and peter Bons are pretty close. It could be better by adding their ideas. – JeffBusterCase Dec 03 '20 at 10:45

1 Answers1

0

This can be done in various ways, which are mentioned below:

  1. By identifying in which App Service your App is running - name your app service with a prefix or suffix as dev or prod. You can further have environment-wise App Insights in this case.

  2. By adding a static variable (Let's say environment) in your Web.Config and setting it as dev or prod while deploying through pipelines/manually (whichever way you are doing). Now, read this setting using below code:

    Configuration["environment"]
    
  3. By using slots, but this method will allow you to just identify any two environments in one App Service, and not more than that (more environments in this case will require more than one App Service).

Harshita Singh
  • 4,590
  • 1
  • 10
  • 13