Introduction:
Here I will explain how to use multiple web.config files in single application using asp.net
Description:
I attended one interview at that time they asked one question that is it possible to use multiple web.config files in single asp.net application? For that question answer is Yes we can use multiple web.config files in single web application but how? By creating web.config file in sub root folders we can use multiple web.config files in our application but each folder should contains only one web.config file. Here I will explain step by step how we can use multiple web.config files in our application.
Here I will explain how to use multiple web.config files in single application using asp.net
Description:
I attended one interview at that time they asked one question that is it possible to use multiple web.config files in single asp.net application? For that question answer is Yes we can use multiple web.config files in single web application but how? By creating web.config file in sub root folders we can use multiple web.config files in our application but each folder should contains only one web.config file. Here I will explain step by step how we can use multiple web.config files in our application.
First create one new web application that contains Default.aspx page and one web.config file. Now right click on your application and select New folder after creation of new folder right click on new folder select Add new item and add one aspx page and one web.config file to this folder that files structure like this
After that write the following code in root folder web.config file appsettings section like this
<appSettings> <add key="rootfolder" value="Root Folder web.config"/> <add key="test1" value="Testing the application for root folder web.config"/> </appSettings > |
After that open Default.aspx page in root folder and write the following code
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>RootFolder web.config</title> </head> <body> <form id="form1" runat="server"> <div> <b> Root Folder values </b> </div> <br /> <div> AppKey value: <b> <asp:Label ID="lbltxt" runat="server" Text="<%$appSettings:rootfolder %>"/> </b> <br /> Appkey Test value: <b> <asp:Label ID="Label1" runat="server" Text="<%$appSettings:test1 %>"/> </b> </div> </form> </body> </html> |
Now run your application and check the output for root folder
Demo
After that open the sub root folder web.config file and write the following code in appsettings section like this
<appSettings> <add key="subrootfolder" value="Sub Root Folder web.config"/> <add key="test1" value="Testing the application for sub root folder web.config"/> </appSettings > |
After that open ChildPage.aspx page in sub root folder and write the following code
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>SubRoot Folder web.config</title> </head> <body> <form id="form1" runat="server"> <div> <b> SubRoot Folder values </b> </div> <br /> <div> AppKey value: <b> <asp:Label ID="lbltxt" runat="server" Text="<%$appSettings:subrootfolder %>"/> </b> <br /> Appkey Test value: <b> <asp:Label ID="Label1" runat="server" Text="<%$appSettings:test1 %>"/> </b> </div> </form> </body> </html> |
Now run your application and check the output for sub root folder
Demo
If you observe above outputs Default.aspx page getting values from root folder web.config file and ChildPage.aspx page getting values from subroot folder web.config file.
In this way we can use multiple web.config files in asp.net web application. I hope it helps you
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
20 comments :
teri maa di lun saleya bunfd mraaa fude ch vadh k .....aide utte charh.....
this is helpful site....... :)
thanks..
if i want to have multiple keys in a single web.config in root but the keys may be duplicate & path is different for the value of keys is it possible??
Thanks in advance reply soon......
Excellent Blog Suresh,Really i like very much, keep rocking
What is the use of making multiple web.config files in Web Application and can we make different connection string in the different web.config files having the same key
But,
i want to link two number of web application to another web application (that is to the third one.), to access that two apps data to the third one. Please do the needful.
Narendran
9940678414
which is first working web.config root or subroot?
i want only one web.config call at the time what i am doing?
pls tell me
Really nice article..but i want to know that how to get the value defined in subroot web.config file from rott aspx page and similarly to get the value of root web.config file to subroot folder
sureshbhai your arrticles are very good.plz publih one article regrading how to do URL Rewritting in asp.net c# using httpmodules and using rewriter tag..Thanks in advance.....
I am searching for the Form authentication via the different web cofig.........Sorry, It is not use ful to me......
Error:Server Error in '/webconfig' Application.
The application setting 'rootfolder' was not found in the applications configuration.
this kind error i got .i dont know what i do please help me
Server Error in '/webconfig' Application.
The application setting 'rootfolder' was not found in the applications configuration.
i got this error .please help me.
Thanks for ur articles
it help us a lot
Not Usefull Two webconfig..
Two connection strings are usefull in one webcinfig..
What is the use full in usage of multiple web config files in single application.
Thanks in advance.. i m waiting for you reply,
yes
nice articles thaks sir
If we access root folder web config key value from sub folder page how we can access
Note: Only a member of this blog may post a comment.