Senior & Expert .Net Developers Discussion Forum by Nyros Technologies

HIRE .Net Expert Developers Programmers Coders From India
Ruby on Rails PHP .Net Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

Dynamically change AppSettings values in ASP.Net using C#?

 
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> Programming with C#
View previous topic :: View next topic  
Author Message
Teena



Joined: 28 Aug 2007
Posts: 143

PostPosted: Mon Mar 01, 2010 10:25 am    Post subject: Dynamically change AppSettings values in ASP.Net using C#? Reply with quote

Hi All,

Is it possible to change AppSettings values of my application? If, provide me a code snippet to do changes in my web.config.

Following is my web.config file.

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="SetupRan" value="true"/>
<add key="WebServer" value="IIS"></add>
</appSettings>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to enable ASPX debugging. Otherwise, setting this value to
false will improve runtime performance of this application.
Set compilation debug="true" to insert debugging symbols (.pdb information)
into the compiled page. Because this creates a larger file that executes
more slowly, you should set this value to true only when debugging and to
false at all other times. For more information, refer to the documentation about
debugging ASP.NET files.
-->
<compilation defaultLanguage="c#" debug="true">
<compilers>
<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs" compilerOptions="/d:DEBUG;TRACE"/></compilers>
<assemblies>
<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
<!-- AUTHENTICATION
This section sets the authentication policies of the application. Possible modes are "Windows",
"Forms", "Passport" and "None"
-->
<authentication mode="Windows"/>
<!-- AUTHORIZATION
This section sets the authorization policies of the application. You can allow or deny access
to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
(unauthenticated) users.
-->
<identity impersonate="true"/>
<authorization>
<deny users="?"/>
<!-- Allow all users -->
<!-- <allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
<!-- CUSTOM ERROR MESSAGES
Set mode="on" or "remoteonly" to enable custom error messages, "off" to disable. Add
<error> tags for each of the errors you want to handle.
-->
<customErrors mode="RemoteOnly" defaultRedirect="error.aspx">
</customErrors>
<xhtmlConformance mode="Legacy"/></system.web>
</configuration>

In my above file, I want to change values of setran in Appsettings section.


Thanks for your help in Advance...
Bye.....
Back to top
View user's profile Send private message
Raghavendra



Joined: 21 Aug 2007
Posts: 222

PostPosted: Mon Mar 01, 2010 10:28 am    Post subject: Reply with quote

Hi Teena,

In ASP.Net, WebConfigurationManager provides the access to change web applications configuration files. Following is the sample code.

Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");

AppSettingsSection appSettings = (AppSettingsSection)configuration.GetSection("appSettings");



if (appSettings != null)

{

appSettings.Settings["SetupRan"].Value = "true";

configuration.Save();

}

That's it.

Thanks & Regards,
Raghavendra K.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert .Net Developers Discussion Forum by Nyros Technologies Index -> Programming with C#
Page 1 of 1


 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts Exceptional Manger
1 suraj 26 Thu Sep 02, 2010 8:52 am
Rahul View latest post
No new posts background image for UITableView
0 kumar 31 Wed Sep 01, 2010 10:34 am
kumar View latest post
No new posts Types of Run time exceptions
1 Dheeraj 30 Wed Sep 01, 2010 8:58 am
venkat View latest post
No new posts Access Web Page content in Windows Forms without WebBrowser
3 mouli 258 Wed Sep 01, 2010 7:31 am
rajesh View latest post
No new posts Explain Interlocked Class & Daemon Thread's?
1 mukundh 53 Wed Sep 01, 2010 7:19 am
setty View latest post
No new posts Life Cycle Of Delegate
0 vinay 29 Wed Sep 01, 2010 7:14 am
vinay View latest post
No new posts Accessing methods defined in another page
1 suraj 30 Tue Aug 31, 2010 12:45 pm
Rahul View latest post
No new posts How ASP.Net events are processed?
1 Teena 33 Tue Aug 31, 2010 11:55 am
suraj View latest post
No new posts Universal description discovery and integration
1 Dileep 25 Tue Aug 31, 2010 11:45 am
venkat View latest post
No new posts What is the difference between Shadowing and Overriding ?
1 suraj 35 Tue Aug 31, 2010 11:37 am
Teena View latest post




Hire an expert .Net developer / coder / programmer or development team from India now!!

Other Forums : Ruby on Rails   ::   PHP   |   Free unlimited HTML CSS templates download

Nyros Technologies   |   Kakinada City Portal   |   Developers Blog   |   About .Net Experts   |   More