testing production config files in non-prodution environment
What is the best way to test production only config files before they are deployed to produciton?
The config files for non production environment could get easily tested in their respective environments. But how can be production environment tested before production deployment happens?
For example, the DB name in STAGE is different than the DB name in prod.
What if STAGE config file has correct DB name and is tested okay. Now, the prod config file has "typo" in the config file. This typo will not be discovered until its deployed in production.
开发者_运维技巧Is there a way to test this config file with typo error before it goes to production?
thanks
The method some use is to have a Staging environment which is identical in every way to your production environment.
You can test in an as-near-as-possible Production environment before going completely live with the solution.
You have to make sure that the configs for the environments are similar in that most of the values are by default with only a subset having to be overriden in the configuration files ( convention over configuration. )
You must be having a PREPROD or STAGING or PROD like environment where the deployment is exactly same as PROD with the config files being identical, except for some values like the machines info. Deployment to PREPROD gives you confidence in such cases that PROD config is fine.
The above two should help you a lot. You can also look at A-B deployment or Blue-Green deployment
Under appSettings
in the web.config file, I use this key:
<add key="CurrentEnvironment" value="0"/>
<!--
Public Enum Environments
Development = 0
Alpha = 1
ReleaseCandidate = 2
Production = 3
End Enum
-->
And as you can see in my comments, this corresponds to an Enum in my Helpers.vb class that is used like so:
Public Shared CurrentEnvironment As Environments = DirectCast(WebConfigurationManager.AppSettings("CurrentEnvironment"), Environments)
This allows you to write Environment specific code such as URLs, Database Connections, etc.
I've found it super helpful.
-- sorry for the VB.NET code, but I'm sure you can covert easily --
EDIT based on the OP edit:
Why don't you create a Unit Test project?
Probably the best way to achieve this is create a separate web site in your production environment as a "stage". Then you can roll your new config to this site first to test it and if everything looks OK migrate it over to your real production site. Otherwise, you can't be guaranteed it will behave the same as being on your production server.
精彩评论