刷新Web.config文件 [英] Refresh Web.config file

查看:113
本文介绍了刷新Web.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要在下面的代码中刷新我的应用程序中的web.config文件的内容我有一个用户定义的函数,它没有更新我的.config文件中的Delay值

  if (dsTime.Tables [ 0 ]。Rows.Count >   0 
{
System.Configuration.Configuration web = System.Web。 Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
web.AppSettings.Settings.Remove( 延迟);
web.AppSettings.Settings.Add( 延迟 + dsTime.Tables [ 0 ]。行[ 0 ] [ ExDurSec]。ToString( )+ );
// web.AppSettings.Settings.Add(Delay,+ 240 * 1000 + );
web.Save(ConfigurationSaveMode.Modified);



}

我的表

 ID ExName ExDurSec ExDurMin 
1 DatabaseSystems 9000000 15
3 分析系统 1800000 30
5 数学 1200000 20





如果我选择数据库系统,我有一个下拉列表控件来选择考试,考试时间将是9000000秒持续时间..然后在web.config文件中,该值将存储为='''9000000''以运行9000000秒的检查,即:15分钟..

此处的问题是用户是否选择另一个考试分析系统然后是web.config文件下的值l存储为180000作为30分钟,但它不是一次存储..只有当我再次刷新页面时才存储...我希望我的要求现在很清楚..请找到任何解决方案



Web.config文件

 <   appSettings  >  
< add key = 延迟 = 60000 / >
< / appSettings >

解决方案

检查CodeProject中提到的同一问题的答案 - 如何使用c#编辑Web.config文件 [ ^ ]。



在网站运行时,您不应该存储需要在web.config中刷新的任何数据。修改web.config文件,刷新该Web应用程序的应用程序池,如果存储在进程会话状态模式下,会话数据将丢失。

您可能想要查看您的设计。


页面在您的浏览器上 - 它没有直接链接到部署应用程序的Web服务器。服务器上的web.config更改后,它不会自动刷新。当你更改web.config然后在服务器上应用程序重新循环。在这种情况下你会丢失会话 - 但只要你不做任何事情,你的页面就会保持不变。



如果需要持续刷新,你可以写一些客户端脚本,每隔几秒钟就可以强制页面或部分页面重新加载。像板球比分一样。



您可以在onload活动中注册类似的内容。



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





您可以通过此链接。



http://www.w3schools.com/js/js_timing.asp [ ^ ]


请关注此URL

http://msdn.microsoft.com/en-us/library/bb861909(v = office.14).aspx [ ^ ] [ ]

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

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

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

<appSettings>
  <add key="Delay" value="60000" />
 </appSettings>

解决方案

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.


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.

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



This link you can go through.

http://www.w3schools.com/js/js_timing.asp[^]


Please follow this URL
http://msdn.microsoft.com/en-us/library/bb861909(v=office.14).aspx[^][]


这篇关于刷新Web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆