Event Reciever run with elevated previledges
-
06-12-2019 - |
Domanda
I created one event receiver and deployed it, but only users who are site collection admins are able to view this web part. I have included the SPSecurity.RunWithElevatedPrivileges but the same thing. What am I missing?
Below is my code
public override void ItemAdding(SPItemEventProperties properties)
base.ItemAdding(properties);
SPSecurity.RunWithElevatedPrivileges(delegate()
{SPWeb web = properties.OpenWeb();
base.ItemAdding(properties);
string name= web.Lists[properties.ListId].Fields["first name"].InternalName;
var list = web.Lists["location names"];
});}
Soluzione
You should recreate context.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using(SPSite site = new SPSite(properties.SiteId))
{
using(SPWeb web = site.OpenWeb(properties.Web.ID))
{
//code
}
}
});
Altri suggerimenti
Please make sure that your solution is a farm solution, not a sandbox solution.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange