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





Click to Enlarge


Add controls on page

















Code




<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";
  conf.Save();
}
//set session value
protected void Button3_Click(object sender, EventArgs e) {
  Session["ID"] = 4;
}



Output



Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250