Click here to Skip to main content
15,301,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i need to refresh the content of the web.config file in my application in my below code i have a user defined function which is not updating the value of Delay in my .config file
C#
if (dsTime.Tables[0].Rows.Count > 0)
            {
                System.Configuration.Configuration web = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
                web.AppSettings.Settings.Remove("Delay");
                web.AppSettings.Settings.Add("Delay", "" + dsTime.Tables[0].Rows[0]["ExDurSec"].ToString() + "");
                //web.AppSettings.Settings.Add("Delay", "" + 240 * 1000 + "");
                web.Save(ConfigurationSaveMode.Modified);   

}
My Table
SQL
ID ExName              ExDurSec           ExDurMin
1  DatabaseSystems     9000000             15
3  Analytics Systems   1800000             30
5  Mathematics         1200000             20


I have an Dropdown list control to select the exams if i select Database Systems the exam duration will be 9000000 in secs of Duration..then in web.config file the value will store as='9000000' to run the exam for 9000000 secs ie:15 minutes..
The problem here is if the users selects another exam Analytics systems then the value under web.config file will store as 1800000 as 30 minutes but it is not storing at once..it is storing only if i refreses the page again ...I hope my requirement is clear now..please find any solution

Web.config file
XML
<appSettings>
  <add key="Delay" value="60000" />
 </appSettings>
Posted
Updated 20-Feb-13 15:05pm
v3
Comments
S. M. Ahasan Habib 19-Feb-13 10:36am
   
Why web config file refresh/reloaded is needed? If anything add/modify/delete any data in web.config file the web.config file cache automatically expired with app pool recycled. Please review your problem before go for solution.
sahmed3 20-Feb-13 0:53am
   
Hi Habib,
In my online examination application the java script timer function calculates the timing function in decreasing order in seconds based on the web.config file <appsettings> Value="60000" the code calculates it for 60 secs. if i change the value of the appsettings it not get reflected untill i refreshed the page..please find the soln... i not clear i vil give in description..

Check the answers to the same question asked here in CodeProject - How to edit the Web.config file using c#[^].

You shouldn't be storing any data that needs to be refreshed in web.config while the site is running. Modifying the web.config file, refreshes the app pool for that web application and your session data will be lost if stored inproc session state mode.
You may want to review your design.
   
v2
Page is on your browser - which has no direct link to the web-server where the application is deployed. It won't refresh by-itself after web.config changes at server. when you change the web.config then on server the application re-cycles. You will lose session in that case - but as long as you don't do anything your page will remain as it is.

For continuous refresh you can write some client side scripting where after every few seconds you can force your page or a portion of it to re-load. Something like cricket scores.

You could register something like following in your onload event.

JavaScript
window.setInterval("javascript:window.location.reload( true );", 300000); 


This link you can go through.

http://www.w3schools.com/js/js_timing.asp[^]
   
   
Comments
Ankur\m/ 19-Feb-13 8:07am
   
That's a sharepoint link. In asp.net changing web.config refreshes app pool. Which means all your session data are gone, if you are using inproc session state. I am not sure if this can be done, but I am sure, this isn't recommended.
sahmed3 20-Feb-13 0:54am
   
Hi Habib,
In my online examination application the java script timer function calculates the timing function in decreasing order in seconds based on the web.config file <appsettings> Value="60000" the code calculates it for 60 secs. if i change the value of the appsettings it not get reflected untill i refreshed the page..please find the soln... i not clear i vil give in description..
Ankur\m/ 20-Feb-13 1:26am
   
As I have already told in my answer, your design seems wrong to me. Don't store that value in the web.config file rather store it in database or in Application object or in a flat file.
And my name is not Habib.
Asim Mahmood 19-Feb-13 8:15am
   
check this link
http://www.c-sharpcorner.com/UploadFile/5c0d33/key-and-values-dynamically-in-web-config-file/
Yes you are right Ankur\m session will lost but and it's not recomeded but may be he has some scenario like that.
sahmed3 20-Feb-13 0:54am
   
Hi asim,
In my online examination application the java script timer function calculates the timing function in decreasing order in seconds based on the web.config file <appsettings> Value="60000" the code calculates it for 60 secs. if i change the value of the appsettings it not get reflected untill i refreshed the page..please find the soln... i not clear i vil give in description..
Asim Mahmood 20-Feb-13 1:44am
   
Yes Habbib i agreed with you but it's Ahmed requirements.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900