Using different Web.config in development and production environment

前端 未结 10 2236
梦如初夏
梦如初夏 2020-11-22 12:50

I need to use different database connection string and SMTP server address in my ASP.NET application depending on it is run in development or production environment.

<
10条回答
  •  甜味超标
    2020-11-22 13:31

    On one project where we had 4 environments (development, test, staging and production) we developed a system where the application selected the appropriate configuration based on the machine name it was deployed to.

    This worked for us because:

    • administrators could deploy applications without involving developers (a requirement) and without having to fiddle with config files (which they hated);
    • machine names adhered to a convention. We matched names using a regular expression and deployed to multiple machines in an environment; and
    • we used integrated security for connection strings. This means we could keep account names in our config files at design time without revealing any passwords.

    It worked well for us in this instance, but probably wouldn't work everywhere.

提交回复
热议问题