开发者

Store & Return Settings for a Webpage

So I am using C# ASP.NET 3.5 and I would like to add a feature to my site to turn on and off a sort of debug mode for testing purposes.开发者_如何学Python

Is there a best way to have a file or class that stores or returns simply if myDebug is on or off. It has to be accessed fast since it will be used a lot on multiple pages and it should be easy to set using the website itself.

My first thought is just a class with get/set which is stored on every page... perhaps the master page?

Thanks for any input -Scott


Sounds like something you'd want to put in AppSettings in your web.config.

(I'm assuming that setting compilation debug to true in web.config is insufficient for what you're trying to do.)


Use AppSettings.

You can get your app settings like so:

string appSettingValue = ConfigurationManager.AppSettings["key"];

You can change your app settings like so.

Code below has been copied from blog link above to show as sample:

private void ChangeAppSettings(string key, string NewValue) 
{ 
Configuration cfg; 
cfg = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); 

KeyValueConfigurationElement setting = (KeyValueConfigurationElement)cfg.AppSettings.Settings(key); 

if ((setting != null)) { 
setting.Value = NewValue; 
cfg.Save(); 
} 
}

You might have to call ConfigurationManager.RefreshSection("appSettings"); after the save to have the app see the changes.... Im not sure if the cfg.Save() will reload/refresh the settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜