473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

modifying web.config programmatically

Hi,

Is there a .Net control available that allows to write into web.config file
appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create the
encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but how
to write there?

Thank you

Vadim
Nov 18 '05 #1
8 2322
as long as the site isn't being accessed just use/edit as you would any text
file.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config file appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create the encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but how to write there?

Thank you

Vadim

Nov 18 '05 #2
You might want to investigate using the registry to store the sensitive
information.

HOW TO: Use the ASP.NET Utility to Encrypt Credentials and Session State
Connection Strings

http://support.microsoft.com/default...b;en-us;329290

"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config
file
appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create
the
encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but
how
to write there?

Thank you

Vadim


Nov 18 '05 #3
You don't. The configuration files are for static data. The place for
dynamic data is in memory, or a database of some kind.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config file appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create the encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but how to write there?

Thank you

Vadim

Nov 18 '05 #4
You would be changing the web.config file and restarting the web
application. If someone is using the web app - your winform app would
terminate their session. Web.config is for static data only.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config file appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create the encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but how to write there?

Thank you

Vadim

Nov 18 '05 #5
Thank you, everybody for your replies.

The idea is to configure database connections and write the configuration
information into web.config, the utility will be used by end users. They
will install the ASP.NET application and the utility will be also installed
into the same directory. They will run the utility and it will create
encrypted entries in web.config. I want to make it as easy for the end user
as possible, I wouldn't want to go into registry.
I used to do the same thing with ini files for win 32 applications, it was
easy to write encrypted database connection settings into ini files from a
program that does encryption.

The information is static because the db connections will be very seldom
reconfigured.

"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config file appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create the encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but how to write there?

Thank you

Vadim

Nov 18 '05 #6
You'll have to read it in like any other xml file. This is chopped out
of a larger function, but you get the idea:

XmlDocument configXmlDoc = new XmlDocument();
configXmlDoc.Load("web.config");

XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");

for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
// parse conn string
Regex connStringRegex = new
Regex("SERVER=(.*);DATABASE=(.*);UID=(.*);PWD=(.*) ;",
RegexOptions.IgnoreCase);
Match match = connStringRegex.Match(oValue.Value);
dbServerText.Text = match.Groups[1].Captures[0].ToString();
dbNameText.Text = match.Groups[2].Captures[0].ToString();
dbUserText.Text = match.Groups[3].Captures[0].ToString();
dbPasswordText.Text = match.Groups[4].Captures[0].ToString();
}
}

// write the config settings
XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");

for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
oValue.Value =
string.Format("SERVER={0};DATABASE={1};UID={2};PWD ={3};",
dbServerText.Text, dbNameText.Text, dbUserText.Text,
dbPasswordText.Text);
}
}

configXmlDoc.Save("Web.config");
-Jason

vadim wrote:
Thank you, everybody for your replies.

The idea is to configure database connections and write the configuration
information into web.config, the utility will be used by end users. They
will install the ASP.NET application and the utility will be also installed
into the same directory. They will run the utility and it will create
encrypted entries in web.config. I want to make it as easy for the end user
as possible, I wouldn't want to go into registry.
I used to do the same thing with ini files for win 32 applications, it was
easy to write encrypted database connection settings into ini files from a
program that does encryption.

The information is static because the db connections will be very seldom
reconfigured.

"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config


file
appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create


the
encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but


how
to write there?

Thank you

Vadim


Nov 18 '05 #7
Hi Jason,

I figured out that I can just edit web.config as an ordinary xml file, but
your example will help me to do this,
also should I use full path to the web.config file in the load and save
calls?

Thank you very much

Vadim
"Jason DeFontes" <ja***@defontes.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
You'll have to read it in like any other xml file. This is chopped out
of a larger function, but you get the idea:

XmlDocument configXmlDoc = new XmlDocument();
configXmlDoc.Load("web.config");

XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");

for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
// parse conn string
Regex connStringRegex = new
Regex("SERVER=(.*);DATABASE=(.*);UID=(.*);PWD=(.*) ;",
RegexOptions.IgnoreCase);
Match match = connStringRegex.Match(oValue.Value);
dbServerText.Text = match.Groups[1].Captures[0].ToString();
dbNameText.Text = match.Groups[2].Captures[0].ToString();
dbUserText.Text = match.Groups[3].Captures[0].ToString();
dbPasswordText.Text = match.Groups[4].Captures[0].ToString();
}
}

// write the config settings
XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");

for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
oValue.Value =
string.Format("SERVER={0};DATABASE={1};UID={2};PWD ={3};",
dbServerText.Text, dbNameText.Text, dbUserText.Text,
dbPasswordText.Text);
}
}

configXmlDoc.Save("Web.config");
-Jason

vadim wrote:
Thank you, everybody for your replies.

The idea is to configure database connections and write the configuration information into web.config, the utility will be used by end users. They
will install the ASP.NET application and the utility will be also installed into the same directory. They will run the utility and it will create
encrypted entries in web.config. I want to make it as easy for the end user as possible, I wouldn't want to go into registry.
I used to do the same thing with ini files for win 32 applications, it was easy to write encrypted database connection settings into ini files from a program that does encryption.

The information is static because the db connections will be very seldom
reconfigured.

"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config


file
appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create


the
encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but


how
to write there?

Thank you

Vadim


Nov 18 '05 #8
Yeah, if your executable isn't in the same directory as the web.config
then you'll need the path, I just left that part out for simplicity.

-Jason

vadim wrote:
Hi Jason,

I figured out that I can just edit web.config as an ordinary xml file, but
your example will help me to do this,
also should I use full path to the web.config file in the load and save
calls?

Thank you very much

Vadim
"Jason DeFontes" <ja***@defontes.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...
You'll have to read it in like any other xml file. This is chopped out
of a larger function, but you get the idea:

XmlDocument configXmlDoc = new XmlDocument();
configXmlDoc.Load("web.config");

XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");

for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
// parse conn string
Regex connStringRegex = new
Regex("SERVER=(.*);DATABASE=(.*);UID=(.*);PWD=(. *);",
RegexOptions.IgnoreCase);
Match match = connStringRegex.Match(oValue.Value);
dbServerText.Text = match.Groups[1].Captures[0].ToString();
dbNameText.Text = match.Groups[2].Captures[0].ToString();
dbUserText.Text = match.Groups[3].Captures[0].ToString();
dbPasswordText.Text = match.Groups[4].Captures[0].ToString();
}
}

// write the config settings
XmlNodeList oList =
configXmlDoc.SelectNodes("configuration/appSettings/add");

for(int i = 0; i < oList.Count; i++)
{
XmlAttribute oKey = oList[i].Attributes["key"];
XmlAttribute oValue = oList[i].Attributes["value"];
if(oKey.Value == "ConnectionString")
{
oValue.Value =
string.Format("SERVER={0};DATABASE={1};UID={2};P WD={3};",
dbServerText.Text, dbNameText.Text, dbUserText.Text,
dbPasswordText.Text);
}
}

configXmlDoc.Save("Web.config");
-Jason

vadim wrote:

Thank you, everybody for your replies.

The idea is to configure database connections and write the
configuration
information into web.config, the utility will be used by end users. They
will install the ASP.NET application and the utility will be also
installed
into the same directory. They will run the utility and it will create
encrypted entries in web.config. I want to make it as easy for the end
user
as possible, I wouldn't want to go into registry.
I used to do the same thing with ini files for win 32 applications, it
was
easy to write encrypted database connection settings into ini files from
a
program that does encryption.

The information is static because the db connections will be very seldom
reconfigured.

"vadim" <va***@domain.com> wrote in message
news:icvoc.430681$Pk3.140361@pd7tw1no...
Hi,

Is there a .Net control available that allows to write into web.config

file
appsettings section?

The idea is to create encrypted user name and password for database
connection and then use them from ASP.Net. The program that will create

the
encrypted entries is a simple winform app.

ConfigurationSettings.appsettings allows to read web.config sections but

how
to write there?

Thank you

Vadim



Nov 18 '05 #9

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

Similar topics

0
by: Keith | last post by:
Is it possible to modify the file properties of a file programmatically? For example, every file, when you right click has a properties option, then from that you can select the summary tab and...
1
by: Stewart Armbrecht | last post by:
Does anyone know of an example application that demonstrates how to edit a web.config file programmatically using c#?
2
by: TK | last post by:
What's the best way to edit web.config programmatically? I want to have an aspx page as a GUI for web admins to modify the roll-base security portion of the web.config(s) on a server. please...
1
by: Fredrik Celin | last post by:
Hello. Is there anybody who knows how I can change som information in the machine.config in a deployment project for a web application? Do I have to change replace the file with a new (and how...
2
by: Kevin Jackson | last post by:
Is there a .NET framework call(s) or technique that allows one to programmatically find the machine.config file.
4
by: jasiglam | last post by:
Using the visual studio.net text editor, I know how to enter/change the "key/value" in the app.config file, for example: key="SqlConnection1.ConnectionString" value="data source=Boomer;initial...
1
by: Vincent | last post by:
The subject says it all...I keep trying to modify one of my reports programmatically. The new controls are added to the report successfully, but if I try to do anything with the report, such as...
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
6
by: Andrew Jocelyn | last post by:
Hi How do I programmatically change (read/write) the values in this app.config file at runtime? Specifically I want to change the client endpoint address but it would be nice to change other...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.