Microsoft ASP.NET Programming with MS Visual C# .NET
Problem for Microsoft ASP.NET Programming with MS Visual C# .NET

!-- Web.Config Configuration File -->




By barbarsaini on Mar 17, 2009

" "
!-- Web.Config Configuration File -->






Clarification Request

Posted by kd24911 on Mar 17, 2009

hi,

What is the problem ?
Can you ellaborate?

Thanks.

Solution #1

posted on Jun 09, 2009
Somewhat Helpful)

saumyar

Rank: Wiz 
Rating: 78%, 119 votes
What Is web.config?

The web.config file is the application’s configuration file. It is typically used to configure an ASP.NET Web application and define the configuration settings for the Web application. It typically contains the application-wide settings, such as database connection string, culture settings, authentication, and authorization information, etc. In ASP.NET 1.x, much effort was required to manipulate the web.config file programmatically. With ASP.NET 2.0 however, this can be done quite easily and efficiently. The following section discusses how this can be achieved.

The Configuration API in ASP.NET 2.0
The configuration API of ASP.NET 2.0 adds a great level of flexibility in that it allows us to add or edit a configuration file seamlessly in ASP.NET. The WebConfigurationManager class in the System.Web.Configuration namespace has the OpenWebConfiguration method that can be used to open the configuration file of the application as a Configuration object for reading from or writing to the configuration file. The virtual path to the configuration file is specified to this method as a parameter. The following code snippet displays all the keys of the appSettings section of the web.config file:

Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettingsSection =
(AppSettingsSection)configuration.GetSection("appSettings");
if (appSettingsSection != null)
{
foreach (string key in appSettingsSection.Settings.AllKeys)
{
Response.Write(key);
}
}

The following method can be used to modify a specific key — value pair of the web.config file — programmatically using C#:

public void Modify(string key, string value)
{
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
if (appSettingsSection != null)
{
appSettingsSection.Settings[key].Value = value;
config.Save();
}
}

The following method can be used to delete a specific key in the web.config file programmatically using C#:

public void Remove(string key)
{
Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
if (appSettingsSection != null)
{
appSettingsSection.Settings.Remove(key);
config.Save();
}

}

Was this helpful?
Yes
No

Popular Solutions for Microsoft ASP.NET Programming


Questions and Unsolved Problems for Microsoft ASP.NET Programming


Do you recommend Microsoft ASP.NET Programming with MS Visual C# .NET?
Answer

Answer
how do i forward an email to several contacts?

Answer
I have downloaded matlab but when I try to run it it comes up with ''error starting desktop''

Answer
I have an SLC 5/04 for my cpu and connect to a PanelView 500 for touchscreen interaction. With all... (More)

Answer
This is not exactly a Problem, but advise seek. We have developed an e-commerce website selling... (More)


Didn't find what you were looking for?

Describe your problem:

Select a Category:







Ask our Experts

 

Solve Your Problem Now!
Chat Live with an Expert
Chat Now
Browse popular Problems
More Common Problems
Most Common Problems for:
For Microsoft ASP.NET Programming...:

Top Programming Tool Experts

Rank: Guru Guru  

Solutions: 1454
Member Since: July 2009

Experience: I have owned a computer networking sales and service company.

Ask Me
Find more Programming Tool Experts

Top Computer & Laptop Repair

(877) 729-0812
We connect to your computer over the Internet to...
Remote Repair

(513) 874-3306
We fix and repair laptop motherboard no video, no...
LaptopOnCall Inc.


       
Solve Your Problem Now!
Chat Live with an Expert
Chat Now

X
Continue
When the original poster rates a solution that was given to his own problem, that rating is locked!
X

Are you sure the solution content is Inappropriate?
   
Tech buddies can communicate directly to answer questions. Become a Tech Buddy and have direct access to your favorite expert for FREE!
Insert Link
Insert Image
Insert You-Tube clip
Insert List
Insert List
Spell Check

What is this?



Select