How To Read A Settings Value From The Web.config File In Application
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
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
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
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
Nov 11, 2010
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 Replies
Oct 30, 2010
I 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 ?
View 4 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
Sep 22, 2010
I am designing a web application for Leave Application of our faculties. There is a form in my website which represent the existing paper-back leave application form. Users(faculties) have to fill-up this web form and after validation an email will be send to the email address of our principal/hod. I hope that email address(s) will be provided to our group members. Now I want to know that what will be the required configuration of the web.config file? I found this blog ScottGu's Blog. Here the given configuration is:
[Code]....
But I think this is not acceptable for my project as the smtp from="test@foo.com", userName, password are unknown to me. So what should I do. Am I able to understand my requirement to you?
View 4 Replies
Jul 22, 2010
I'm working on a new C# web application in Visual Studio 2010, and am having problems reading a value in Web.Debug.Config from the GLobal.asax.cs file.
In the Application_Start event I've got the following code:
Application.Add("AppID", ConfigurationManager.AppSettings.Get("AppID"));
I also tried:
Application.Add("AppID", ConfigurationManager.AppSettings["AppID"]);
And in the Web.Debug.Config file I have the following:
<applicationSettings>
<add key="AppID" value="123" />
</applicationSettings>
I also tried:
<appSettings>
<add key="AppID" value="123" />
</appSettings>
And I tried having it in a file path, like so:
<appSettings file="C:MyPathappSettings.config"/>
When running in debugger, I've got a break-point in the Application_Start event in Global.asax.cs. It hits the break point, but in all cases the value coming back from ConfigurationManager is coming back null. What am I doing wrong?
View 3 Replies
Feb 9, 2010
My asp.net app has is using a web.config for common configuration. I also have a section that maps some data objects to connection strings, and that section is going to be couple thousand of lines. I want to move that section to another config file "dataMappings.config", so I don't bulk up web.config - is there a standard mechanism of accessing that config file?
View 1 Replies
Nov 12, 2010
I've been thinking about this for a couple days but still would like some feedback on the best way to go about this:
I have multiple sites (domains) that will be running the same code. However, there are a couple settings I have in the appsettings web.config file which are relative to each site. (ie: defaultSiteTitle, emailFromAddress, etc).
I would like to deploy this application in only one location (folder) and point the domains in IIS to that one directory.
To do this, I believe I cannot use the web.config file to hold these settings...
So, I decided to make a SiteSettings.xml file and load the site settings in there:
<sites>
<oSite domain="abc.com" defaultSiteTitle="This is Site ABC" emailFromAddress="info@abc.com" />
<oSite domain="xyz.com" defaultSiteTitle="This is Site XYZ" emailFromAddress="info@xyz.com" />
</sites>
So when I need to access the site settings I just call a function in my datalayer that reads this xml file and via the httpRequest I pass it it determines which site settings to use.
Okay, that works when I call it from a page where I have the httpRequest...
Howver, now when I'm into some business layer functions say sendEmail and I need to find the emailFromAddress from the SiteSettings.xml file, I don't have the httpRequest. I know I could probably hack something together and pass it someway...
But I'm trying to figure out the best way to do this...
I don't really want to store it into session.
Is it possible to tell IIS what web.config file to look at, if I had multiple web.config files? (I don't think this is possible).
View 2 Replies
Apr 30, 2010
Web.config is the main settings and configuration file for an ASP.NET web application. The file is an XML document that defines configuration information regarding the web application. The web.config file contains information that control module loading, security configuration, session state configuration, and application language and compilation settings. Web.config files can also contain application specific items such as database connection strings
Example 1:
<!-- This is an example Web.config file -->
[Code]....
In this article, we will see how to read the configuration settings in the web.config using 'JavaScript'.
Step 1: Create a new ASP.NET website. Add a button control to the Default.aspx.
Step 2: Right click the project > Add New Item > Web Configuration File
Add the following sample entry to the appSettings section in the web.config between the <configuration> tag as shown in the example 1:
<add key="var1" value="SomeValue"/>
Step 3: To read these entries using JavaScript, add the following script in the <head> tag of your Default.aspx page as shown below:
<head runat="server">
<title></title>
<script type="text/javascript">
function ReadConfigSettings()
{
var v1 = '<%=ConfigurationManager.AppSettings["var1"].ToString() %>'
alert(v1);
}
</script>
</head>
Step 4: Call this function on a button click and display the values of the configuration settings
<input type="button" value="Get" onclick="ReadConfigSettings();" />
That's it. Run the application and click the button. The value of the key in the appSettings will be displayed in the alert window. I hope you liked this short article.
View 7 Replies
Jun 17, 2010
I have this portion of my web.config file;
[Code]....
I need to be able to retrieve the value of "from" in my application. How do I read this value into my code?
View 3 Replies
Sep 20, 2010
I have few settings which I could place in a separate XML file and have them accessed in the Web app. Then I thought (thinking of one additional file to deploy), why not have them in the web.config itself. However, just because I need to have custom nodes, I can not have the settings under . So, I am thinking of creating a custom config handler following this. Would that be better than having a separate XML file? Is It going to be an overkill or performance wise? Is there a better way to go?
View 1 Replies
Mar 19, 2011
How to run asp.net application with encrypted web.config ,is it possible note that ASP.NET application have a database with encrypted connectionstring and a "cannot read connection string " message is generated
View 2 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
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
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
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
Jan 19, 2011
I have a .NET 4 class library project, which is used by multiple web projects. In this class library I need to get a DB connection string and it needs to be the same for all the web projects. Currently I've got it as a setting in each web.config file, but this is not ideal. Is there any way I can have that configuration stored with the DLL, but still allow it to be modified at runtime (ie. hardcoding the connection string is out)?
App.config seems to be generally ignored for a DLL, even though it does get renamed to assemblyname.dll.config and copied to the bin directory for the web. I tried making it an "application setting" (ie. using the auto-generated class derived from System.Configuration.ApplicationSettingsBase) and this appeared to work, but changing the value in the DLL .config file at runtime had no effect, so I suspect it's really just using the hardcoded default value of the setting.
View 3 Replies
Aug 21, 2010
I have a web app where user uploads a file.ile is saved in server locally and I want to read some data from it.Currently my development server has office 2003.So do I need office 2007 in order to be able to read an excel from office 2007 ?
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wrkBook; // = new Microsoft.Office.Interop.Excel.Workbook();
View 3 Replies