locked
AppSetting Web.config Question RRS feed

  • Question

  • User-507786106 posted

    I need to determine if the website is running on TestServer or Devloper's Server.  I  am using appSettings to get set the file path,

    What code do I use to determine which server I am on? How do I detect the server?

    Codes

     Test Server

    System.Configuration.ConfigurationManager.AppSettings["TESTServerPath"].ToString();

    Developer Server

    System.Configuration.ConfigurationManager.AppSettings["DevServerPath"].ToString();

    Tuesday, June 18, 2019 2:52 PM

Answers

  • User753101303 posted

    The file path of what ? It could be maybe the same on distinct servers ? I would use a single System.Configuration.ConfigurationManager.AppSettings["EnvironmentName"] value which would be "Production" or "Development". From now when  doing something and even when not using ASP.NET Core you may want to have a look at how it is done in this version: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.2 and do something similar.

    Else it seems your intent would be to compare Server.MapPath("~/") to both AppSettings["TESTServerPäth"] and AppSettings["DevServerPath"] ???

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 18, 2019 2:56 PM

All replies

  • User753101303 posted

    The file path of what ? It could be maybe the same on distinct servers ? I would use a single System.Configuration.ConfigurationManager.AppSettings["EnvironmentName"] value which would be "Production" or "Development". From now when  doing something and even when not using ASP.NET Core you may want to have a look at how it is done in this version: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-2.2 and do something similar.

    Else it seems your intent would be to compare Server.MapPath("~/") to both AppSettings["TESTServerPäth"] and AppSettings["DevServerPath"] ???

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 18, 2019 2:56 PM
  • User1520731567 posted

    Hi slimbunny,

    slimbunny

    I need to determine if the website is running on TestServer or Devloper's Server.

    If you want to determine TestServer or Devloper's Server,

    You could try to use HostingEnvironment.IsDevelopmentEnvironment Property to check TestServer or Devloper's Server.

    Its explanation is: ‘Gets a value that indicates whether the current application is in a development environment.’

    For example: you could check the value of HostingEnvironment.IsDevelopmentEnvironment in BaseController and handle based on your need.

    Best Regards.

    Yuki Tao

    Wednesday, June 19, 2019 6:02 AM