Create Custom Webconfigs in Asp.Net MVC
Here are some highlighted notes on creating a custom web-config, that I wrote after finding a very quick and easy solution to. Overall the process is very easy to get started just I felt pictures were needed because the solution I found lacked any.
Without editing, and by default Asp.net MVC comes with a Debug and Release config but since I like to create a QA stage for my configurations with all my application another webconfig needs to be added.
Now right click on the project solution and go to properties, this will bring up the configuration manager. You can also just click on the build tab shown in the second image below.
Almost done, as you can see in the results that the configuration can be used but there is no visible webconfig in your solution explorer. Now right click on your "Web.config" and select "Add Config Transform".
Bonus!
Incidentally I discovered that Visual Studio allows you to preview the configuration differences from each config to the base config. Simply right click on your custom config and in the dropdown select "Preview Transforms"
Problem I found and faced
After while playing around with the Configuration Manager, I began to rename things and delete them to see if this would break any of my configurations or some other components.Two problems that I thought would occur was that the Configuration Manager could point to a webconfig that no longer existed.
Start of our Application |
Now right click on the project solution and go to properties, this will bring up the configuration manager. You can also just click on the build tab shown in the second image below.
Configuration Manager/Properties |
Under the configuration tab and inside the dropdown simply select "New" and add in your custom Config name, for this article I just name mine example. Important keep the leave the "create new project configurations" check." If not checked you will not be able to Add the webconfig later and will have to remove it and add the config again.
Alternative way to get to the Configuration Manager |
Mission Complete! |
Incidentally I discovered that Visual Studio allows you to preview the configuration differences from each config to the base config. Simply right click on your custom config and in the dropdown select "Preview Transforms"
Problem I found and faced
After while playing around with the Configuration Manager, I began to rename things and delete them to see if this would break any of my configurations or some other components.Two problems that I thought would occur was that the Configuration Manager could point to a webconfig that no longer existed.
Warning Message for deleting Configs |
The second problem was renaming, which actually lead me to a few problems that I could not correct by removing in the Configuration Manager. In my write out for all the cases I found, it is important to note that when I say "config" I don't mean the webconfig. What I mean is the option in your Configuration Manager.
Renaming Cases
Resources
How to create custom web.config in ASP.Net MVC4? - Stack Overflow - The Solution
Web.config File Transformations : The Official Microsoft ASP.NET Site - Preview Tranforms!
Renaming Cases
- Deleting a config and renaming another config to the deleted config.
- The deleted config's webconfig will still exist and the renamed config will still be pointed to that of its webconfig and the webconfig name will not change.
- Renaming a config
- The webconfig will not update its name.
Resources
How to create custom web.config in ASP.Net MVC4? - Stack Overflow - The Solution
Web.config File Transformations : The Official Microsoft ASP.NET Site - Preview Tranforms!