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
2 Asked on January 29, 2021 by tejas-thite
approval process flow microsoft flow power automate sharepoint online
2 Asked on January 27, 2021 by antra-sharma
1 Asked on January 26, 2021 by mark-l
2 Asked on January 26, 2021 by jackie
1 Asked on January 26, 2021
1 Asked on January 25, 2021 by user7268
1 Asked on January 24, 2021 by fmh
0 Asked on January 23, 2021 by sandy-hanna
0 Asked on January 22, 2021 by pepozzo
asset library document library modern experience sharepoint online
1 Asked on January 22, 2021 by user31823
sharepoint enterprise sharepoint foundation sharepoint server
2 Asked on January 21, 2021 by maurizio
4 Asked on January 19, 2021 by extractor
1 Asked on January 17, 2021 by shahid
1 Asked on January 12, 2021 by aquen
3 Asked on January 11, 2021
calculated column calculated column formula sharepoint online
1 Asked on January 11, 2021 by leroy
1 Asked on January 11, 2021
development post sharepoint rest api sharepoint search sharepoint server
2 Asked on January 8, 2021 by user43231
2 Asked on January 8, 2021 by whatsup
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP