C# - Read Variable From Web.Config?
Oct 4, 2010How can I add and read value from web.config
View 4 RepliesHow can I add and read value from web.config
View 4 RepliesWe 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.
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]....
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 RepliesWhich is better from a performance perspective?
Accessing a Global Application Variable (Application["foo"])
versus
Accessing an AppSetting variable from the web.config
Does .NET Cache the AppSetting variables so that it is not accessing the web.config file with every use?
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 RepliesHow to read the app key serviceRefPath key in my web.config
[code]....
Is it possible to access the key?
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 Repliesread the connection string in a web application from a T4 template residing in ANOTHER assembly referenced by the web application. I am generating some code from the database that it references and how to get the connection string for this use. ive read George Js example here however it only works when the template resides in the web app.
View 2 RepliesAfter includeding file.js in ny webpage This script will create a variable within the current javascript context called "Status". This variable can take three values : "On", "Off", "Unknown".How can I read this value on code behind? I am planning to check if the variable is false and if so, make some changes on page.
View 4 RepliesWhen 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");
I called the string in my Data layer
string connectionName = System.Configuration.ConfigurationSettings.AppSettings["Connection"].ToString();
now how could call it in SqlConnection con
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 RepliesI 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.
Can i read data from web.config using JQuery ?
View 3 RepliesI 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 RepliesIs there a way write code in web.config file using preprocessed function. Say I created environment variables like %Temp%, %WINDIR%. order to read these I can use the configurationManager class. But I dont want to use it. I woudl like to use a preprocessed function similar to timeStampPattern="{timestamp(local)}". Here timestamp(local) retrieves the value directly. So in a similar way can i read the environment variables %temp% and %windir% using preprocessed function if any exists?
View 2 RepliesI am unable to understand. Hopefully someone out there has faced a similar issue and knows the fix. I am creating DAL for my project using class library. In my class library I want to store the connection string in APP.Config file and I have created and saved it.
The problem is when I try to access my connection string by name using ConfigurationManager.ConnectionStrings[Name], it returns null. When I try to access connection string using number like ConfigurationManager.ConnectionStrings[0] It returns a strange connection string i.e. (data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true)
I want to clearify here that I have not deployed the website yet and its on my local file system so there is no link of this library with IIS.
<sessionState timeout="1440"></sessionState>
how can i read value of timeout from web.config to c# code
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.
I would like to store a collection of strings in the web.config. This collection would vary in size over time. I would like to be able to pull all of the strings in the collection into an array or collection in code. (.Net 4, asp.net)
i.e.
<customCodes>
<VendorCode vendorName="Name1" code="1234567891234567891324567987ddd" isActive="true"/>
<VendorCode vendorName="Name2" code="1sadfsadf1234567891324567987ddd" isActive="true" />
<VendorCode vendorName="Name3" code="123456789dfadfdsaf3324567987d32" isActive="true"/>
</customCodes>
I could use appsettings with the strings all in one value but I would like to seperate it out for organizational reasons. Not using the key/value pair complicates things a bit. I am now getting a message that states "you can't have duplicate elements in a section"
I've created a web page and it contains some settings value in web.cofig for example images.So i want to give the path of images in Web.Config file and file name in that particular image src. I wanted to read that settings only in aspx page not in codebehind. For example Web.Config: <add key="ImagePath" value=[URL]> and in my aspx page, <img id="ImgHeader" runat="server" src="<%ConfigurationManager.AppSettings["ImagePath"]%>" />
View 2 RepliesI have an ASP.NET site which uses a 3rd party activeX control. I have to pass a few parameters to the OBJECT tag in the HTML page. If i hardcode these parameters into the HTML everything works.
I would like to place the parameters in my web.config with app settings "key/value" pairs.
My problem is i cannot read the app key setting in the HTML markup to succesfully pass them in as parameters. I can read them fine from server side code behind.
What's the correct way to read these settings in the client side HTML markup ?
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.
When executing this line:
Dim roleRedirectSection As LoginRedirectByRoleSection = DirectCast(ConfigurationManager.GetSection("loginRedirectByRole"), LoginRedirectByRoleSection)
...I get the following error:
Message: "An error occurred creating the configuration section handler for loginRedirectByRole: Could not load type 'sitename.LoginRedirectByRoleSection'. (W:Webs2010DEVsitenameASP 4.0web.config line 10)"
<configuration>
<configSections>
<section name="loginRedirectByRole" type="journeyeast.LoginRedirectByRoleSection" allowLocation="true" allowDefinition="Everywhere" />
</configSections>
<loginRedirectByRole>
<roleRedirects>
<add role="Administrator" url="~/Account/Admin/Default.aspx" />
<add role="Employee" url="~/Account/Emp/Default.aspx" />
<add role="Teacher" url="~/Account/Teacher/Default.aspx" />
<add role="Student" url="~/Account/Student/Default.aspx" />
<add role="School" url="~/Account/School/Default.aspx" />
</roleRedirects>