1

I'm trying to modify the web.config file when the feature is activated with the code below:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWebApplication webApp = (properties.Feature.Parent as SPSite).WebApplication;

    SPWebConfigModification modification = new SPWebConfigModification("mode", "system.web/customErrors");
    modification.Owner = "modifyAccountFeatureOwner";
    modification.Sequence = 0;
    modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
    modification.Value = "Off";         
    webApp.WebConfigModifications.Add(modification);

    webApp.Update();            
    webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); 
}

But I'm receiving this error in the step Activate Features:

Error occurred in deployment step 'Activate Features': '' is an invalid expression.

Anyone know what is causing this error?

2
  • SPWebConfigModification modification = new SPWebConfigModification() myModification.Path = "system.web/customErrors"; myModification.Name = "mode";
    – Waqas Sarwar MVP
    Jun 26, 2014 at 19:47
  • Manipulating the web.configs can be a painful job. Is PowerShell an option instead of server-side code? Jun 26, 2014 at 21:49

1 Answer 1

0

try the below code.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    SPWebApplication webApp = (properties.Feature.Parent as SPSite).WebApplication;

    SPWebConfigModification modification = new SPWebConfigModification();
    modification.Path = "configuration/system.web/customErrors"
    modification.Name = "mode"
    modification.Owner = "modifyAccountFeatureOwner";
    modification.Sequence = 0;
    modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute;
    modification.Value = "Off"; 
    webApp.WebConfigModifications.Clear()        
    webApp.WebConfigModifications.Add(modification);

    webApp.Update();            
    webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); 
}
2
  • Thanks for the reply, but didn't work.
    – user20336
    Jun 26, 2014 at 20:33
  • what error you are getting, could you please share complete lof
    – Waqas Sarwar MVP
    Jun 26, 2014 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.