SharePoint Asked by Ola on February 15, 2021
How to deactivate feature from site collection? I am trying the code below but got this error:
Updates are currently disallowed on GET requests. To allow updates on
a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb”.
private void DeactivateProvisioningFeature()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
site.AllowUnsafeUpdates = true;
var feature = site.Features.SingleOrDefault(sf => sf.DefinitionId == new Guid("464b78de-c14e-4c88-bd52-00136fc899f4")); // find delegate control provisioning feature
if (feature != null) //if feature is activated
{
site.Features.Remove(feature.DefinitionId, true); //deactivate feature
}
web.Update();
site.AllowUnsafeUpdates = false;
web.AllowUnsafeUpdates = false;
}
}
}
You do NOT need and you should NOT call web.update()
. This mean that you save this property to the database.
To disable site collection feature, you do not need SPWeb instance also.
If you have permissions to manage features of the site, you also do not need new SPSite object instance.
Try to write you code like, this:
if (SPContext.Current.Site != null)
{
site = SPContext.Current.Site;
site.AllowUnsafeUpdates = true;
//YOUR FEATURE DEACTIVATION CODE
site.AllowUnsafeUpdates = false;
}
Answered by ECM4D on February 15, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP