whityum
asked on
ConfigurationSection properties cannot be edited when locked
I'm trying to add URL Mappings whenever a new page is added to the database, this is the code I have, but it keeps erroring out:
System.Configuration.Confi guration configuration = WebConfigurationManager.Op enWebConfi guration(" ~/Web.conf ig");
UrlMappingsSection ums = (UrlMappingsSection)config uration.Ge tSection(" system.web /urlMappin gs");
UrlMappingCollection umc = ums.UrlMappings;
UrlMapping um = new UrlMapping("~/" + sUrl, pageURL + "?pageID=" + pageID.ToString());
umc.Add(um);
configuration.Save(Configu rationSave Mode.Full) ;
Network Service and ASPNET both have read/write access to the file.
The error is:
Exception Details: System.InvalidOperationExc eption: ConfigurationSection properties cannot be edited when locked.
on the configuration.Save() line
System.Configuration.Confi
UrlMappingsSection ums = (UrlMappingsSection)config
UrlMappingCollection umc = ums.UrlMappings;
UrlMapping um = new UrlMapping("~/" + sUrl, pageURL + "?pageID=" + pageID.ToString());
umc.Add(um);
configuration.Save(Configu
Network Service and ASPNET both have read/write access to the file.
The error is:
Exception Details: System.InvalidOperationExc
on the configuration.Save() line
ASKER
This code is from the microsoft site:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myconf As Configuration = WebConfigurationManager.Op enWebConfi guration(" /ASPNET20C C")
Dim myUrls As UrlMappingsSection
Dim myGroup As System.Web.Configuration.S ystemWebSe ctionGroup = myconf.GetSectionGroup("sy stem.web")
myUrls = myGroup.UrlMappings
myUrls.UrlMappings.Add(New UrlMapping(txtUrl.Text, txtZiel.Text))
If Not myUrls.LockItem Then
myconf.Save()
End If
End Sub
I converted it to C#, and even attempted to unlock the UrlMappingsSection and it still says ConfigurationSection properties cannot be edited when locked
Configuration myconf = WebConfigurationManager.Op enWebConfi guration(" ~/Web.conf ig");
System.Web.Configuration.S ystemWebSe ctionGroup swsg = (SystemWebSectionGroup)myc onf.GetSec tionGroup( "system.we b");
UrlMappingsSection ums = swsg.UrlMappings;
ums.LockItem = false;
UrlMapping um = new UrlMapping("~/" + sUrl, pageURL + "?pageID=" + pageID.ToString());
ums.UrlMappings.Add(um);
ums.SectionInformation.For ceSave = true;
myconf.Save(ConfigurationS aveMode.Fu ll);
return true;
Has anyone added URL Mappings in code successfully?
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myconf As Configuration = WebConfigurationManager.Op
Dim myUrls As UrlMappingsSection
Dim myGroup As System.Web.Configuration.S
myUrls = myGroup.UrlMappings
myUrls.UrlMappings.Add(New
If Not myUrls.LockItem Then
myconf.Save()
End If
End Sub
I converted it to C#, and even attempted to unlock the UrlMappingsSection and it still says ConfigurationSection properties cannot be edited when locked
Configuration myconf = WebConfigurationManager.Op
System.Web.Configuration.S
UrlMappingsSection ums = swsg.UrlMappings;
ums.LockItem = false;
UrlMapping um = new UrlMapping("~/" + sUrl, pageURL + "?pageID=" + pageID.ToString());
ums.UrlMappings.Add(um);
ums.SectionInformation.For
myconf.Save(ConfigurationS
return true;
Has anyone added URL Mappings in code successfully?
ASKER
and lem2802, why do you say that?
there is a whole management API to edit the configuration
http://asp.net/QuickStart/aspnet/doc/management/mgmtapi.aspx
there is a whole management API to edit the configuration
http://asp.net/QuickStart/aspnet/doc/management/mgmtapi.aspx
ASKER
I changed Configuration myconf = WebConfigurationManager.Op enWebConfi guration(" ~/Web.conf ig"); to
Configuration myconf = WebConfigurationManager.Op enWebConfi guration(" /projectNa me");
and it works.
Configuration myconf = WebConfigurationManager.Op
and it works.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you need to edit the file and save overwiting it