I have created the FBA site in SharePoint 2010 Farm. The site is allowing both the windows and FBA authentication. I have set the Server administrator (Member of Built in Administrator) as Application pool identity. The same account has sufficient permission in Sql server database for the site.
I have implemented one feature. The feature in turn is modifying the web.Config for the sites in farm. I have placed the code inside the SPSecurity.RunWithElevatedPrivileges block.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
Guid siteGuid = ((SPWeb)properties.Feature.Parent).Site.ID;
Guid webGuid = ((SPWeb)properties.Feature.Parent).ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteGuid))
{
using (SPWeb web = site.OpenWeb(webGuid))
{
SPWebApplication webApp = web.Site.WebApplication;
SPWebConfigModification myModification = new SPWebConfigModification("add[@name=\"assembly\"]", "/configuration/system.web/compilation/assemblies");
myModification.Value = "<add assembly=\"MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9e00227b2bfdcg7e\"/>";
myModification.Sequence = 0;
myModification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;
myModification.Owner = typeof(<MyWebpartNameGoesHere>).FullName;
webApp.WebConfigModifications.Add(myModification);
webApp.WebService.ApplyWebConfigModifications();
webApp.Update();
}
}
});
}
The Code is running perfectly fine for any windows user. But when I enter the site as FBA user and try to activate the feature, I start getting the “Access denied.” error.
Error: System.Security.SecurityException: Access denied. at Microsoft.SharePoint.Administration.SPPersistedObject.BaseUpdate() at Microsoft.SharePoint.Administration.SPWebApplication.ApplyWebConfigModifications() at Microsoft.SharePoint.Administration.SPWebService.ApplyWebConfigModifications()
Can anyone help me to solve this problem?
You seriously have to consider if you want users to activate this code. Making web.config modifications is an administrators thing and not a users' thing.
Please read this: http://www.itidea.nl/index.php/access-denied-when-activating-a-feature/
Regards, Anita