473,782 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom values in Web.config

Hi!
In old ASP I used Application collection to store configuration settings
like ADO connection string. In .NET, it seems, the preferred method is
using Web.config file. Yes? If I'm right then how to add (manually) and
retrieve (from app) custom values?

Thank you!

P.S. It seems, VS.NET does not have tool to modify Web.config file.
Developer should update this file manually as text?
Nov 19 '05 #1
1 1546
Hi!

Yes, web.config is the file to use. You can also use machine.config for
stuff like connection strings so they won't be stored on a public area. The
config files are XML files, so you can use any XML editor to edit them. ;)

In your web.config file, add an element called <appSettings> between
<configuratio n> and <system.web>, inside the appSettings element, use the
<add/> element to add variables:

<configuratio n>
<appSettings>
<add key="SomeKey" value="SomeValu e"/>
....
</appSettings>
<system.web>
.....
</configuration>

Now you can access these values by the
System.Configur ation.Configura tionSettings class' static AppSettings
property. Like this:

using System.Configur ation;
....
public class MyPage : System.Web.Page
{
....
public void Page_OnLoad()
{
Response.Write( ConfigurationSe ttings.AppSetti ngs.Get("SomeKe y"));
}
....
}
By the way.. Windows Applications can also use config files. Name the file
yourprogram.exe .config and you're up and running. ;)

HTH,
Lars-Erik
"Tumurbaata r S." <sp********@mag icnet.mn> wrote in message
news:eV******** ******@TK2MSFTN GP12.phx.gbl...
Hi!
In old ASP I used Application collection to store configuration settings
like ADO connection string. In .NET, it seems, the preferred method is
using Web.config file. Yes? If I'm right then how to add (manually) and
retrieve (from app) custom values?

Thank you!

P.S. It seems, VS.NET does not have tool to modify Web.config file.
Developer should update this file manually as text?

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3762
by: Geopsaros | last post by:
Hi! I have created a custom trace Listener class, called "DBTraceListener" it works fine when i add it manually in code : (eg. Trace.listeners.add(new DBTraceListener("myDBListener", TraceLevel.Verbose, getDBConnection) ) What I'm trying to achieve now is to add this listener via the MyApplication.exe.config file
7
4755
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
1
5355
by: Hans [DiaGraphIT] | last post by:
Hi! I have problem with passing data to custom action. I don't know what wrong I'm doing. I'm trying to follow the steps in the walkthrough: "Passing Data to a Custom Action" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxwlkwalkthroughpassingdatatocustomaction.asp The error I recieve is: "The savedSate dictionary does not contain the expected values and might
2
1526
by: Jarod_24 | last post by:
I Created a .config file for my Web application and named it "Settings.config" The file contains some settings for the application, including a connection string to a database. But i don't see how a System.Configuration. class finds the file. I expected to be doing something like this:
4
1922
by: Nick Gilbert | last post by:
Hi, I would like the ability to store the configuration settings for all versions of my site in a single web.config file by using different sections. Eg: <siteConfig> <machine name="XENON"> <site url="/blog/"> <mode value="live">
3
1717
by: Mads Brydegaard | last post by:
Hi, I have created a custom Config handler for reading a custom config section in my .config file(s) It works very well! I have placed a web.config in my root directory and then I use sub files in sub diretories overriding various settings in the config file. Very nice strategy which really makes it easy to customize generic applications.
7
2922
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*" path="*.sgf" type="CustomExtensionHandler, Extenders.CustomExtensionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d831d925597c1031" validate="True"/> </httpHandlers>
6
2230
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base class would have CurrentUser property that would hold customer class in session and that was fine for all my situations. Now ASP.NET 2.0 came and we have Profile property for pages that could be extended with configuration to have custom...
6
3802
by: Tabi | last post by:
Hi, I want to create a custom section in my web.config that can hold my custom values. I created a section in web.config as written below. <configSections> <section name="myCustomSection" type="ComIT.Applications.Common.ConfigurationSections.MyHandler" allowLocation="true" allowDefinition="Everywhere" /> </configSections>
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.