Articles → .NET → Consequence of changing web.config at runtime

Consequence of changing web.config at runtime

Software requirement

Prerequisite knowledge

Steps of execution

Create a new project

Picture shows the sample project in visual studio

Click to Enlarge

Add controls on page


<asp:Button ID="Button1" runat="server" Text="Get session value"  OnClick="Button1_Click"/>
<asp:Button ID="Button2" runat="server" Text="Change web.config" OnClick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="Set session value" OnClick="Button3_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

//Get session value
protected void Button1_Click(object sender, EventArgs e) {
  Label1.Text = "Current Session value is : " + Session["ID"];
//Change config value
protected void Button2_Click(object sender, EventArgs e) {
  Configuration conf = WebConfigurationManager.OpenWebConfiguration("~");
  conf.ConnectionStrings.ConnectionStrings["ApplicationServices"].ConnectionString = "Test1";
//set session value
protected void Button3_Click(object sender, EventArgs e) {
  Session["ID"] = 4;


Picture displays the effect of changing the web.config file on session variable

Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Tuesday, October 1, 2013


Your Email Id  
Query/FeedbackCharacters remaining 250