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?

  • SPWebConfigModification modification = new SPWebConfigModification() myModification.Path = "system.web/customErrors"; myModification.Name = "mode"; – Waqas Sarwar MVP Jun 26 '14 at 19:47
  • Manipulating the web.configs can be a painful job. Is PowerShell an option instead of server-side code? – Falak Mahmood Jun 26 '14 at 21:49
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(); 
}
  • Thanks for the reply, but didn't work. – user20336 Jun 26 '14 at 20:33
  • what error you are getting, could you please share complete lof – Waqas Sarwar MVP Jun 26 '14 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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