Wednesday, January 1, 2014

Configuration File in .NET

Configuration files allow developers and admins to change application settings as needed without the need to recompile the application. It allows you to define application settings you  can change later which makes the flexible and easy to maintain. config files are XML files. 

There are different types of config files used in .NET. For instance, app.config files in Windows Services, Windows Forms etc. while Web.Config file is used in ASP.NET Web projects and web services. (SO)

A Machine.config and root.config file is located in .NET framework system folder which contains default settings for all websites that run on a server. 

Multiple config files
You can define multiple Web.Config files within different folders of the project. In this way you can have specific configurations for some areas in the application while keeping the global Web.Config file. You can then reference the other config files like below,

 <appSettings configSource="app.config">
 </appSettings>
 <connectionStrings configSource="database.config">

 </connectionStrings>

Securing sections in config files
Ways to store password 
http://www.asp.net/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure

Web.Config file transformations
There are two ways to automate change of Web.config settings. Web.config transformations and Web deploy parameters.

You can use transformations to have different config files for different environments such as development and production. 

Read more about transformations (ASP.NET Site)
Stackoverflow Questions on web config transform
http://stackoverflow.com/questions/305447/using-different-web-config-in-development-and-production-environment

In web.config you can specify debug=true attribute. See why it is bad sometimes.

Configuration sections

configSections (link)
Using this you can define your own configuration sections. This should be the first child element of <configuration> element. Check source here.
http://www.codeproject.com/Articles/10981/Understanding-Section-Handlers-App-config-File

connectionStrings
Used to store connection strings. Find examples at connectionstrings.com.

appSettings (link , linklink)
You can store database connection strings, file paths, etc. You can read app settings entries like in following code

using System.Web.Configuration;

WebConfigurationManager.AppSettings["configFile"]

system.web 

httpRuntime : link
Specifies many different ways to configure web application. See more options.
authentication: specify authentication type (Windows, Forms, Passport etc.)

http://stackoverflow.com/questions/355261/whats-the-difference-between-system-web-and-system-webserver

system.webServer

Handlers 
Is a part of system.webServer
http://www.iis.net/configreference/system.webserver/handlers
http://www.telerik.com/help/aspnet-ajax/web-config-settings-overview.html

ExtensionlessUrlHandler
http://stackoverflow.com/questions/26271958/what-does-extensionlessurlhandler-do-in-an-mvc-application
http://stackoverflow.com/questions/12708113/asp-net-mvc-4-and-extensionlessurlhandler

Extensionless URLs


entityFramework
system.web.extensions
system.net
system.serviceModel
runtime
system.identityModel
system.identitymodel.services
connectionStrings



0 comments:

Post a Comment

Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook