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.
Start of our Application
Without editing, and by default 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.

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
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". 

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
  1. 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.
  2. Renaming a config
    • The webconfig will not update its name.
Regardless of the cases a webconfig's name can not be edited in the configuration manager and will not be updated by it, but you change it in the project's solution file, do this with the project closed. Take caution when renaming and deleting as it can cause some webconfigs to still around. You will see this happen when you delete a webconfig and it appears when adding a "config transform".

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!


Popular posts from this blog

Nginx Best Practices Extended

Installing Windows on Acer chromebook 15 cb3-532

Entity Framework: ToListAynsc & WhereAsync