VS 2008 - Read Value From Config File
Sep 13, 2011
I have code that reads a value from a config file (not web.config) given a key. It looks like this:
Code:
Public Shared Function GetCustomConfig(ByVal ValuetoGet As String, ByVal ConfigFileValue As String) As String
Dim Returnvalue As String = String.Empty
LoadConfig(ConfigFileValue)
For Each KeyValue As String In AppSettings.Keys
If KeyValue = ValuetoGet Then
Returnvalue = AppSettings.Item(KeyValue).ToString
End If
Next
Return Returnvalue
End Function
So if my config file which is named my.config has this entry: <add key="TempArea" value="c:Temp"/>I would call GetCustomerConfig("TempArea", "my.config") and the function would return "c:Temp". Most of the time this is what happens. But sometimes I get an exception: Collection was modified after the enumerator was instantiated.
Is there a better way to get the value given the key? This is code written long ago by my predecessor, and I am not sure I want to use it anymore. If I do use it, I will have to do something so that it is more reliable.
View 7 Replies
Similar Messages:
Jul 8, 2010
I have many Connection strings in my web.config file. I also have a "dataConfiguration" setting in the same file which specifies what database my app connects to.
How do I read the "defaultDatabase" setting / section from the, see below xml file.
<configuration>
<configSections> [code]....
View 2 Replies
Jan 5, 2011
I am developing web applicaiton. I want to read web.config in App.config file. I have appSettings and connectionStrings in web.config. How to read that?
View 10 Replies
Feb 8, 2011
When the user clicks on it, another .aspx page should pop up. I used the code below and it works fine. But when we deploy this .aspx page, the IP address of the target IIS server will be different. So I am thinking of saving the IP address of target IIS server in web.config file and load it into the Window.open method of Javascript code (below).Qusetion 1: Is that right way to do? If so, how I can read web.config file from Javascript?
Code:
<script type="text/javascript">
function open_win() {
window.open("http://10.999.1.86/WebUI/HistoricalRuns.aspx", "_blank", "toolbar=no, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=yes, copyhistory=no, width=1000, height=500");
View 7 Replies
Feb 17, 2011
I'm trying to use OpenExeConfiguration to read a different config file, but I can't find any good examples.I have a windows Service and some of the config data already exists in another windows service config file on the same server, and it makes more sense to use what is already there, rather than have to maintain the same data in 2 places.
View 2 Replies
Mar 9, 2010
I have to duplicate some settings (like connection string) between a web.config file that a WCF host uses and a web.config file that a web client uses.
In the interest of not duplicating, can I have both the web.configs read from a separate xml file? The two web.configs can be entirely in different solutions/projects so I guess this is not possible, but wanted to get other's opinion.
PS: I do understand I can use a database to store all the config settings.
View 4 Replies
Feb 22, 2011
I wonder how often the Web.config file is read by the server?And if the fact of the Web.config file is too large, influences the application performance?
View 2 Replies
Aug 18, 2010
I'm trying to use the following command:
Dim xmlFilePath As String = _
System.Configuration.ConfigurationManager.AppSettings("XmlFilePath")
to retrieve the following setting:
<applicationSettings>
<MySolution.WebProject.My.MySettings>
<setting name="XmlFilePath" serializeAs="String">
<value>C:ASP.NETFolderMessageLog</value>
</setting>
</MySolution.WebProject.My.MySettings>
</applicationSettings>
However, xmlFilePath shows up as Nothing after that line of code is run. What's the correct code to get a setting out of the web.config file in an ASP.NET application?
NOTE: Although you can add keys individually to the <appsettings> tag, I'm trying to figure out how to use it with the "Settings" tab in the project's properties.
View 2 Replies
Jan 3, 2010
Question: I have an annoying problem with nhibernate.The problem is I cannot get any example I find on the web to work... I've now tried for two days...
The first problem was it wouldn't read the config file, so I had to move it into app.config / web.config.
The second problem is that whatever I do, I always get an error:
No persister for: NHibernate.Examples.QuickStart.User
I've searched google and I did change the mapping to embeded ressource, and I did add the mapping to the config file, but nothing helps...
The example is from this page:
https://www.hibernate.org/362.html
I've uploaded my Visual Studio 2005 project to
http://daniel-steiger.ch/exchange/NhibernateCrap.rar
View 2 Replies
Jan 2, 2011
i have a xml configuration file like below format.
<setting>
<web>
<mailid>xxxx</mailid>
</web>
<network>
<logid>sd</logid>
</network>
</setting>
i would like to programmatically read entry from xml config file which is same as asp.net webconfig file reading.
View 2 Replies
Sep 8, 2010
I am trying to read a normal string from the web.config file. When I try to read a string from the web.config file the application doesnt seem to read it. I set my sqlconnection string in the web.config file. It reads a sqlconnection string but not a normal string.Here is my code:
web.config file:
<applicationSettings>
<MyApplication.Settings>
<setting name="Colour" serializeAs="String">
<value> "Red"</value>
</setting>
</MyApplication.Settings>
</applicationSettings
This is how I try to call the setting:
string strColour = Properties.Settings.Default.Colour;
I am using .net framework 4.0
View 2 Replies
May 7, 2015
i need add one key value in web.config and that values read in asp.net page and to bind that value to gridview?
View 1 Replies
May 22, 2012
How to read/open a pdf file from web site existing on remote file share?
View 7 Replies
Nov 15, 2010
I would like to put a value in web.config file in my project and read it programatically from .aspx page.Under which section of web.config file should I save the value. This is not a connectionstring. It is path of a file. And I how can programmatically read the value in the code?I am using C#.
View 3 Replies
Nov 2, 2010
I have a website written in C# that was running fine on one server. We moved it to another server and have a couple issues. I am mainly a VB.NET coder but can do a few things in C#. This is not a project - it is a website and can open it in VS2008 no problem. This is an admin site for the whole website where the user can add customer comments, etc. When logging in, it works fine. I can go to one of the admin pages after logging in and works. If I go to two other different pages, I get this error:
Object reference not set to an instance of an object.
[Code]....
It turns out this is in the main.master page and it is used by the other pages that load fine. The ApplicationTitle variable is set right in the web.config file and like I said, it shows on the other pages.
My question is why would this code work fine for some pages and not two others? All of these admin pages are under a folder called Admin and the web.config file is in the root folder of the website. Its almost like these two pages cannot see the web.config file in the root folder? Why would that be if thats the case?
Btw, when I have this loaded in VS2008 and try to do a Build, it says:
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
I would assume the folders on the server are set right since all but two .aspx pages run fine. Just something I thought I would mention. This does not really seem to be a coding issue but something not set right especially since it ran on the other server just fine.
View 9 Replies
Jan 21, 2011
I would like to use both of the connection strings in the same web.config file how can I do this I tried this yesterday it worked I called it a night, then this morning I got this. The error being on line: 10 Parser Error Message: The entry 'ApplicationServices' has already been added.
Line 8: <add name="ApplicationServices"
Line 9: connectionString="Data Source=Mysource;Initial Catalog=travelatlantic;User ID=MyID; Password=MyPassword;" />
Line 10: <add name="ApplicationServices"
Line 11: connectionString="Data Source=MySource;Initial Catalog=travelatlantic2;User ID=Myid; Password=MyPassword;" />
Line 12: </connectionStrings>
View 8 Replies
Sep 1, 2010
We are experiencing some strange behaviour on one of our ASP.NET web servers (Windows 2003 64-bit). After some activity, two third-party controls are unable to run correctly. One is log4net (it does not write error messages out) and the other is a menu control (it displays eval message instead of picking up its license). The one common thread is that both controls pick up their config from external config files (linked to from web.config).
Just wondering if anyone has any thoughts on this or experienced this in any way. Is it related to file/folder rights? The server has been running fine for a while and just started exhibiting this behaviour. Perhaps it occurs around the time the worker processes are recycled.
View 1 Replies
Nov 2, 2010
I have a website written in C# that was running fine on one server. We moved it to another server and have a couple issues. I am mainly a VB.NET coder but can do a few things in C#. This is not a project - it is a website and can open it in VS2008 no problem. This is an admin site for the whole website where the user can add customer comments, etc. When logging in, it works fine. I can go to one of the admin pages after logging in and works. If I go to two other different pages, I get this error:
Object reference not set to an instance of an object.
[Code]....
It turns out this is in the main.master page and it is used by the other pages that load fine. The ApplicationTitle variable is set right in the web.config file and like I said, it shows on the other pages.
My question is why would this code work fine for some pages and not two others? All of these admin pages are under a folder called Admin and the web.config file is in the root folder of the website. Its almost like these two pages cannot see the web.config file in the root folder? Why would that be if thats the case?
View 3 Replies
Dec 10, 2010
Below is my default "web.config" file whenever I start new web site using Visual Studio 2008. My question:
(1). Has someone hacked my computer and changed the default setting "web.config" in my VS 2008?
(2). How to reset "web.config" file as normal default setup in VS 2008 (better security)?
BELOW IS MY CURRENT SETTING WEB.CONFIG FILE WHENEVER STARTING NEW WEB SITE
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"
/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="false" strict="false" explicit="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<pages>
<namespaces>
<clear />
<add namespace="System" />
<add namespace="System.Collections" />
<add namespace="System.Collections.Generic" />
<add namespace="System.Collections.Specialized" />
<add namespace="System.Configuration" />
<add namespace="System.Text" />
<add namespace="System.Text.RegularExpressions" />
<add namespace="System.Linq" />
<add namespace="System.Xml.Linq" />
<add namespace="System.Web" />
<add namespace="System.Web.Caching" />
<add namespace="System.Web.SessionState" />
<add namespace="System.Web.Security" />
<add namespace="System.Web.Profile" />
<add namespace="System.Web.UI" />
<add namespace="System.Web.UI.WebControls" />
<add namespace="System.Web.UI.WebControls.WebParts" />
<add namespace="System.Web.UI.HtmlControls" />
</namespaces>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<authentication mode="Windows" />
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
View 3 Replies
Mar 30, 2010
I'm preparing to deploy a ASP.NET web application. The target server has already a previous version of my web application with parameters specified on the web.config file.
In the new version of this web application, the web.config file contains new sections I would like they appear into the target web.config file on the server.
However I can't find the way to merge the new web.config sections into the existing web.config file ?
Does I have to do it programmatically, or is there a tool to merge the both files during installation ? (I'm using Web Setup Project).
View 2 Replies
Jul 26, 2010
I have one doubt Can we access one web.config file to another web.config file in asp.net
View 6 Replies
Feb 16, 2011
Currently, I work on an ASP.NET project which is hosted under version control and is used on several developer machines, tester machine and production environment.
In three cases, configuration (Web.config) may be different. For example, developer and tester environments use testing SQL Server, whereas in production environment, another SQL Server is accessed, so the connection string is different in those cases.
We want to keep three versions of Web.config in subversion. But modifying each of three files every time we need to add, remove or change a common setting is annoying: it would be nice to have a common, master Web.config, which will be inherited by each of the three Web.config files.
How to set up an ASP.NET project which will use a master configuration file and different slave configuration files on different machines, thus sharing the same project/source code/configuration files in subversion?
View 2 Replies
Feb 2, 2011
I have a web site that was done in asp.net 2.0 along with visual studio 2005. I've recently upgraded to VS 2008 and I'm haveing an issue with the namespaces in the web.config file not registering. Specifically, references to system.web and microsoft.visualbasic.
View 3 Replies
Nov 8, 2010
How to read the app key serviceRefPath key in my web.config
[code]....
Is it possible to access the key?
View 2 Replies
Sep 24, 2010
I know how to read a stuff from web.config in .cs file, but how can i read something .aspx source? For example i want to do next <a href="somethingFromWeb.config"></a>
View 1 Replies