TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Change Daynamic Web.config File
Zaid Ansari
Oct 26
2015
Code
1.1
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Add Reference
using
System.Configuration;
using
System.Web.Configuration;
Out Put Data Web.config File
<appSettings>
<add key=
"TEST"
value=
"123"
/>-----------------------------------------Change Value
<add key=
"webpages:Version"
value=
"2.0.0.0"
/>
<add key=
"webpages:Enabled"
value=
"false"
/>
<add key=
"PreserveLoginUrl"
value=
"true"
/>
<add key=
"ClientValidationEnabled"
value=
"true"
/>
<add key=
"UnobtrusiveJavaScriptEnabled"
value=
"true"
/> </appSettings>
C# Code
public
JsonResult WebConfigChange()
{
var configuration = WebConfigurationManager.OpenWebConfiguration(
"~"
);
//Get All Data Web.config File
var Section = (AppSettingsSection) configuration.GetSection(
"appSettings"
);
// Get <appSetting>
Section.Settings[
"TEST"
].Value =
"123"
;
//Value Replace
configuration.Save();
//Replace Web.config File
return
Json(
new
{
Data =
"Success"
}, JsonRequestBehavior.AllowGet);
}
Web.config
ASP.NET