webconfigurationmanager

Loading a ConfigurationSection with a required child ConfigurationElement with .Net configuration framework

烈酒焚心 提交于 2019-12-22 03:32:28
问题 I have a console application that is trying to load a CustomConfigurationSection from a web.config file. The custom configuration section has a custom configuration element that is required. This means that when I load the config section, I expect to see an exception if that config element is not present in the config. The problem is that the .NET framework seems to be completely ignoring the isRequired attribute. So when I load the config section, I just creates an instance of the custom

How to retrieve web.config setting in web application subfolder

*爱你&永不变心* 提交于 2019-12-12 03:08:56
问题 I have a subfolder in my web application. It's not a separate application, just a subfolder, but it has its own web.config. There is an aspx page in that subfolder which needs to access a setting in the web.config file in its own folder. When I call ConfigurationManager.GetSection("settingname") from a static initializer on that aspx page, it returns null. Why might this happen? Could it be that my setting name is wrong or that the application root web.config is being accessed instead of the

ASP.NET: HttpRuntime.Cache getting flushed when saving WebConfigurationManager — Is this a bug?

倖福魔咒の 提交于 2019-12-11 08:49:32
问题 Recently, I've been experimenting with caching objects with HttpRuntime.Cache and I was generally under the impression that if I "added" something to the cache like this: HttpRuntime.Cache.Insert("Test", "This is a test!", null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, new CacheItemRemovedCallback(FileChanged)); that the "NotRemovable" and "NoExpiration" flags would keep the object in-memory for the duration of the application. But was finding

read custom config file in asp.net

*爱你&永不变心* 提交于 2019-12-08 03:17:17
问题 How do I read connection strings from custom config file (say abc.config) using WebConfigurationManager from asp.net's C# code? Configuration conf = WebConfigurationManager.OpenWebConfiguration("~/abc.config"); This doesn't seem to work. 回答1: I dont think you can read it with webconfigurationmanager. you will have read like any xml file as it is an xml file public static string GetSingleValue(string strXPathExpression, string strAttributeName) { XmlNode node = GetNode(strXPathExpression); if

Differences in behavior between System.Web.Configuration.WebConfigurationManager and System.Configuration.ConfigurationManager

岁酱吖の 提交于 2019-11-30 12:10:20
问题 I had some trouble on a test server with an ASP.NET website. I goofed, and had the home directory of the Default Web Site pointed to the wrong place. When I tried: ConfigurationManager.ConnectionStrings["connectionString"]; it returned null, but using System.Web.Configuration; /* ... */ var rootWebConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); rootWebConfig.ConnectionStrings

How to OpenWebConfiguration with physical path?

十年热恋 提交于 2019-11-30 05:51:16
问题 I have a win form that creates a site in IIS7. One function needs to open the web.config file and make a few updates. (connection string, smtp, impersonation) However I do not have the virtual path, just the physical path. Is there any way I can still use WebConfigurationManager? I need to use it's ability to find section and read/write. System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration 回答1: You will have to map the physicalPath to a virtualPath. Here is how you would do

Differences in behavior between System.Web.Configuration.WebConfigurationManager and System.Configuration.ConfigurationManager

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 02:09:55
I had some trouble on a test server with an ASP.NET website. I goofed, and had the home directory of the Default Web Site pointed to the wrong place. When I tried: ConfigurationManager.ConnectionStrings["connectionString"]; it returned null, but using System.Web.Configuration; /* ... */ var rootWebConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); rootWebConfig.ConnectionStrings.ConnectionStrings["connectionString"].ConnectionString;` returned the correct connection string. What are all the

Can someone provide a quick App.config/Web.config tutorial?

假装没事ソ 提交于 2019-11-28 23:58:56
I've used these two configuration files many times before, but I've never taken the time to fully understand how they really work. As most people do, I understand the basics in how to call WebConfigurationManager.AppSettings["key"] to get config values. Here are some questions I came up with: What happens when you reference a configuration value within a class library, and the library is part of a bigger solution? Does the app.config need to be copied to the output directory in order for the variables to be found? (I assume yes) Can you directly use a configuration value from an app.config in

Can someone provide a quick App.config/Web.config tutorial?

ぐ巨炮叔叔 提交于 2019-11-27 15:08:38
问题 I've used these two configuration files many times before, but I've never taken the time to fully understand how they really work. As most people do, I understand the basics in how to call WebConfigurationManager.AppSettings["key"] to get config values. Here are some questions I came up with: What happens when you reference a configuration value within a class library, and the library is part of a bigger solution? Does the app.config need to be copied to the output directory in order for the

What's the difference between the WebConfigurationManager and the ConfigurationManager?

旧城冷巷雨未停 提交于 2019-11-26 18:43:39
What's the difference between the WebConfigurationManager and the ConfigurationManager ? When should I use one over the other? UPDATED I just looked at the WebConfigurationManager , and for some reason, you can't access the connection strings as you do in the ConfigurationManager (like an array). Can anyone tell me why MS made it like this? It seems to be a pain to get the connection string you need using the WebConfigurationManager . UPDATED AGAIN with CAVEAT! If you don't have a reference to the System.Configuration namespace added to your project, then Visual Studio will show an error when