Monday, March 28, 2011

My blog post is appearing on Microsoft Official ASP.NET site.

Today I got a surprise from the Microsoft. One of my friend Hajan Informed me that my blog post is appearing on the Microsoft Official asp.net site www.asp.net. This is great surprise and honor for me that my blog post are appearing on Microsoft official site.

MicrosoftASP.NET

I would like to thanks all the peoples who are supporting me and all the people who are their to correct me If I am wrong. Thank you once again!!. I will continue to writing my blogs to serve community and this kind of encouragement give more boost for writing blogs.

Stay tuned for more.. I will keep writing.. Thank you readers..

Technorati Tags: ,
Shout it
Share:
Wednesday, March 23, 2011

Working with more then one web.config files in asp.net application.

Recently one of reader of my blog how we can work with more then one web.config files in asp.net application. So I decided to blog about that. Here is the my reply for that.

You can work with more then one web.config file in asp.net. But you can not put more then one web.config in each folder. Let’s first understand the hierarchy of web.config and other configuration file settings. On the top of the every configuration files you will have machine.config file which will have all system wide configuration settings.You can find this file in your OS drive like C: /windows/Microsoft.NET/vFrameworkNumber/Config folder. Here framework number with what ever framework you are using 1.1/2.0 or 4.0. You can override those settings in web.config file at the your application root folder. Same way you can add more web.config file in subfolder and can override the setting of parent folder web.config file. So we will hierarchy like below.

Hirerchay

Now let’s Create Project for it. In that I have create two web.config and 2 pages. First I have putted the web.config in root folder and then I have putted web.config in subfolder. Same way I have created a sub folder and then I have putted the web.config in sub folder. I have also putted one asp.net page in root as well as subfolder to use respective web.config settings. Here are my folder structure like below.

FolderStructure

Below is code for root folder web.config

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<appSettings>
<add key="root" value="This is from root web.config"></add>
<add key="MySetting" value="This my settings is from root web.config"></add>
</appSettings>

</configuration>

and following is code for sub folder web.config.

<?xml version="1.0"?>
<configuration>
<system.web>
</system.web>
<appSettings>
<add key="sub" value="This is from sub web.config settings"></add>
<add key="MySetting" value="This my settings is from sub folder web.config"></add>
</appSettings>
</configuration>


After that I have written a code in root asp.net page to print settings from web.config folder like this following.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MoreWebConfig
{
public partial class Root : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("Root"));
Response.Write("<BR>");
Response.Write(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("MySetting"));

}
}
}

Same way I have wrriten code in subfolder like following.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MoreWebConfig.SubFolder
{
public partial class SubFolderPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("Sub"));
Response.Write("<BR>");
Response.Write(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("MySetting"));

}
}
}

Now let’s run the both pages in browser one by one and you can see root folder application page is fetching settings from root folder web.config while sub folder application page is fetching setting from subfolder web.config even if key ‘mysetting’ is same on both as expected. You can see out put in browser below.

Root.aspx

Root

SubFolderPage.aspx

SubFolder

So it’s very easy to work with multiple web.config. The only limitation of this you can not access sub folder web.config settings from root folder page. Except all you can use anything. Hope you liked it. Stay tuned for more..Happy programming..


Technorati Tags: ,
Shout it
kick it on DotNetKicks.com
Share:
Monday, March 14, 2011

TSQL Quiz 2011 on beyondrelational.com

One of the my friend Jacob Sebastian running a SQL Server TSQL quiz on his site beyondrelational.com. This is a great opportunity to learn TSQL and win great price Like Apple IPad and other lots of cool stuff. So if you are expert and if you learning TSQL then its a great way to test your knowledge.

For whole month of march selected quiz master will ask a question and you have to answer all this question day by day and at the end of month you will have great chance to win Apple Ipad.

For more details you can visit following link:

http://beyondrelational.com/quiz/SQLServer/TSQL/2011/default.aspx

Hope you liked it.Stay tuned for more..

Shout it
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews