How To Improve CM.AppSettings References

Mar 3, 2010

ASP.NET 3.5 Classes throughout our solution referenced ConfigurationManater.AppSettings[""] to get appSettings (from web.config).

We decided we weren't happy with that. Folks were mistyping appSetting key names in code (which compiled fine), and it was cumbersome to track usages. And then there's the duplicated strings throughout the codebase as you reference the same appSettings all over the place.

So, we decided that only one class would be allowed to reference the ConfigurationManager, and the rest of the solution would reference that class when it needed the value of a certain appSetting. ConfigurationManater.AppSettings[""] was static, so we exposed a bunch of static read-only properties off of our single Settings class.

[Code].....

And now we're injecting the ISettings instance as a dependency of the objects which use settings values (the class/interface are in a project that everyone can reference without problems).

In places where we can't inject an existing instance (e.g. Global.asax), we construct a new instance into a static field.

Given all of that, what would you recommend we change, and why?

View 1 Replies


Similar Messages:

Configuration :: Can't Access AppSettings From Web.config - ConfigurationSettings.AppSettings Is Empty?

Jun 12, 2010

i have stored settings in the AppSettings section of the web.config file.

I'm trying to access these settings via System.Configuration.ConfigurationSettings.AppSettings, but the AppSettingsCollection is empty. So I can't access this settings.

The strange thing is that this is working on my development machine, but is failing on the production machine. Previous versions of the web application have also worked on the production machine. I'm not aware of any modifications that could couse this.

I have also tried using ConfigurationManager and WebConfigurationManager without success.

View 5 Replies

C# - AppSettings Vs ApplicationSettings. AppSettings Outdated?

Feb 28, 2010

I've got some question about two ways to save settings in the web.config.

Appsettings:

Look in web.config
<appSettings>
<add key="key1" value="value1"/>
<add key="key2" value="value2"/>
</appSettings>

Usage in code-behind:

ConfigurationManager.AppSettings["key1"];
ApplicationSettings/ Properties (autogenerated by using the 'properties'-tab in the project)
Look in web.config
<applicationSettings>
<Projectname.Properties.Settings>
<setting name="Testenvironment" serializeAs="String">
<value>True</value>
</setting>
</Projectname.Properties.Settings>
</applicationSettings>

Usage:

Properties.Settings.Default.Testenvironment

So, what the difference between these two storage possibilities of settings in the web.config? As far as I can see, a downside of the appSettings is that you have modify the web.config yourself and the appSettings are not strong tiped, where as the applicationSettings are. Both are replaceable with in a web deployment project.As far as I am concerned, there is no use for appSettings. Am I missing something here? Which is the historically seen older one?

View 1 Replies

C# - SQL Server Reporting Services: Web References Versus Assembly References, Poor Performance

Feb 16, 2010

I am using Reporting Services to render a report directly to PDF. It requires that I use two web references: ReportExecution2005.asmx and ReportService2005.asmx. The performance on web references seems really poor. Since my web server (IIS7) and my SQL Server (2008) are on the same box, is there a way I can reference them directly? If not is there any way I can explicitly cache them or something. First load is really really slow, second load is perfectly acceptable.

View 2 Replies

JavaScript - Mvc Script And Style References / Include Script And Style References That Will Not Break On Deployment

May 11, 2010

I'm trying to include script and style references that will not break on deployment, however I can not even get the references to work locally. I have tried using Url.Content() and MVCContrib's <%=Html.ScriptInclude("")%>.

My scripts are in a Scripts folder on the root of the site; my styles are in the usual Content/css/ folder.

The scripts render like this:

<script type="text/javascript" src="/Scripts/MicrosoftAjax.debug.js" ></script>

This will not work in a view page in the Views folder. What am I doing wrong and what is the best way to handle this?

I would have thought Url.Content() would at least work for styles but used in my master page, the link rendered

<link href="/Content/css/Site.css rel="stylesheet" type="text/css" />

This does not work, because the Master Page is in a Shared folder, so what is really the way forward with this?

View 2 Replies

Web Forms :: Use ConfigurationManager.AppSettings For SRC?

Aug 25, 2010

I've set an AppSetting key for my root directory in my web.config file and now I'm going back through my site and changing all link and resources to use this key. Then If the domain ever changes I can just change one line of code and not worry about links breaking. I'm not quite sure however how to use this when I register my header and footer user controls.

View 2 Replies

What Is AppSettings.configuration File

Feb 16, 2010

What exactly we have in appSettings.config file. My company is using this file in the code to differentiate between Development and Production Environment.

View 10 Replies

What Is The Differences Between Connectionstring And Appsettings

Jun 16, 2010

in one of the application i have been reffering connection string is stored in appsettings! till now i have been storeing the connection in <connectionstring/> element. But, what is the correct way?

So my quetion is, What is the differences between <connectionstring> and <appsettings> in web.config, are there any specific reason why i should or should not be storing connection string in appsettings? Are there any rules / guidlines provided to follow? Or is this completely the choice of the developer?

View 4 Replies

ASP MVC - ConfigurationManager Cannot Find Appsettings?

Oct 27, 2010

I am using MS Test to test one of my controller's actions. This method uses the ConfigurationManger to read appSettigns from the web.config. For some reason ConfigurationMangager is not able to find the appsettings.In NUNIT I would just make sure to add a copy of the webconfig file to the test project so that it is available when running in that context. However this is not working for me.

View 1 Replies

C# - AppSettings Fallback / Default Value?

Sep 21, 2010

For each appSetting I use, I want to specify a value that will be returned if the specified key isn't found in the appSettings. I was about to create a class to manage this, but I'm thinking this functionality is probably already in the .NET Framework somewhere?

Is there a NameValueCollection/Hash/etc-type class in .NET that will let me specify a key and a fallback/default value -- and return either the key's value, or the specified value?

If there is, I could put the appSettings into an object of that type before calling into it (from various places).

View 3 Replies

Configuration :: Appsettings ConfigSource?

Jun 24, 2010

I have splitted the appSettings from web.config file and put it under 'App_ConfigappSettings.config' which is mapped using configSource attribute.web.config :

[Code]....

It is working fine in my local machine. But giving problem while hosting the application to web server.i.e, Can not find appsettings

View 3 Replies

C# - ConfigurationManager.AppSettings Getting Null?

Nov 25, 2010

i did not realize that: i have a web.config in a separate class library and i was reading the web.config appsetting from different web applicaiton.

i am using VS2010 target framework 3.5

i dont know what is wrong here but i am getting null when i try to get

ConfigurationManager.AppSettings["StoreId"];
string _storeid = GetStoreId;
public static string GetStoreId
{
get
{
return ConfigurationManager.AppSettings["StoreId"];
}
}
<appSettings>
<add key="StoreId" value="123" />
</appSettings>

View 3 Replies

Getting AppSettings Values From Web.config In Javascript?

Apr 30, 2010

[Code]....

</script>

In the span's onclick handler i wrote "javascript: alert(getAppSetting('ftpuser'));" for testing, and built some alerts into the function. The first alert returns [object]. That's nice, i thought. The second alert returned 0. That's strange, because the web.config has exactly 1 of this node. So i guess that the function doesn't actually load the correct document. Has anyone done something similar ? When i don't suppy a full path, doesn't javascript assume that it should look for the file in the virtual directory of the current web application where the web.config is ?

View 3 Replies

Which Has Better Performance - Configuration In AppSettings Or Database

Jan 21, 2011

I should store application configuration data and default text values that will have the best performance overall. For example, I've been sticking stuff like default URL values and the default text for error messages or application instructions inside the web.config, but now I'm wondering if that will scale...

View 4 Replies

How To Update Appsettings From An Aspx Page

Aug 8, 2010

I have customer specific settings in a custom.config which links back to web.config.

What I want to accomplish is to load the settings from appsettings section in custom.config into setup.aspx page. The settings will be loaded into textbox, dropdown list etc. After the user makes changes then save it back to custom.config. Is this possible? It seems to me that the appSettings section is readonly. What would be best approach to accomplish this?

View 2 Replies

Web.config Appsettings Not Picked Up In Sub Directory?

Jan 25, 2010

I have a web.config in a sub directory with an appSetting in it. It does not seem to be picked up and added to the appSettings collection? what I'm doing wrong or how to get round setting directory specific settings?

The directory has this config file

[Code]....

And its picked up (or not) by an ascx control like so

[Code]....

View 7 Replies

Access To Web.config Attributes (not AppSettings)?

Mar 23, 2011

given that I can add various addributes to the stock membership provider I assume I can do the same with my own provider implementation.

<add name="MyMembershipProvider" type="Portal.Infrastructure.MyMembershipProvider"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
[...] />

My question now: How do I access these values in the code? I understand that the ConfigurationManager can be used to access key value pairs in the appSettings section but this is different.

View 1 Replies

Configuration :: ConfigurationManager.AppSettings Exception?

Feb 11, 2011

I am retrieving value from webconfig file.

PriceCode = ConfigurationManager.AppSettings[d.PriceCode].ToString() == "" ? "XXXX" : ConfigurationManager.AppSettings[d.PriceCode].ToString(),

if the value is found its fine, but if the value is not found in webconfig file an exception is thrown... why is that?

View 5 Replies

Web Forms :: System.ConfigurationManager.AppSettings - Get Data From?

Mar 1, 2010

I am maintaining some Asp.net code and need some help figuring something out. Basically I have a C# statememt that reads as follows

String Em = System.ConfigurationManager.AppSettings.Get("EmailAddress")

So something tells me it is trying to read an email address. I looked in the web.config file and I don't see the string "EmailAdress" defined in the <appsettings> tags or anywhere else. Could I be looking in the wrong web.config file? Or where is system.ConfigurationManager.AppSettngs looking for the definition of the email address?

View 5 Replies

Passing AppSettings To External JavaScript File?

Dec 1, 2010

I have settings in AppSettings (web.config) and I need to pass them to an external javascript file.

In ASP.NET I would think of an ASHX handler to write the javascript file to the response replacing placeholders with the settings values.

View 1 Replies

Reading And Writting Keys To Appsettings In WebConfigEditor?

Mar 2, 2011

I am just a beginner in the world of programming and I need to work on the following requirement:

My project contains web.config file and an external appSettings file. I am making a WebConfig Editor that has options to Read AppSettings key from web.config and external appSetting file to display them on webPage. Also, I am allowing user to delete any key by clicking on Remove button. Moreover, user can also update any key's value by clicking on update button.Or he can also insert new key by clicking on Add New Key button.

The key issue I am facing is that whenfever I try to add a new key , it gets inserted into web.config file as expected , but at the same time it adds all the keys present in external appSettings file into web.config ( which is abrupt behavior). How to stop this migration of keys from external appSettings file to web.config on any key's update / delete/ add function?

View 2 Replies

.net - Possible To Localize The AppSettings Information In Web.config File?

Apr 6, 2010

I have something like this in mind:

<appSettings>
<add key="ConfigName" value="configuration" culture="1033" />
<add key="ConfigName" value="konfiguracja" culture="1045" />

[code]...

View 4 Replies

Put Custom AppSettings Web.config Data Into The ApplicationState?

Mar 7, 2011

I've got some custom values in the AppSettings, in my web.config file.

These values get checked upon every Request.

eg.

So if every request checks the web.config file for the value of this key, would be be smart to put this into the Application cache (eg. via the global.asax) instead of checking this value EVERY request?

I'm assuming that when we read a value from the AppSettings, the website does a physical read of the web.config file? or is this information also all read into Memory when the website starts up and all references to any appSettings information is just an inmemory read .. not a disk I/O read?

View 2 Replies

How To Improve Coding

May 7, 2010

how can i do perfect coding using all oops concepts?

View 6 Replies

ConfigurationManager.AppSettings Returns Null When Web.config Is Placed In Parent Dir

Jan 5, 2011

I am facing an amazing problem in ASP.NET. I have a website with many sub directories. The sub directories have aspx and aspx.cs files but do not contain web.config files. I am using the web.config file of the parent directory for storing config items for the respective code files in sub directories. But when i m trying to read the web.config using ConfigurationManager.AppSettings[] with absolutely the correct keys, there's no value being returned. Most amazing fact is, this same code works fine in dev enviroment but not in staging.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved