Acceso denegado cuando se utiliza RunWithElevatedPrivileges?
-
27-09-2019 - |
Pregunta
Quiero usuario normal puede acceder a la "Lista de información de usuario" en el sitio raíz MiSitio. Estoy usando "RunWithElevatedPrivileges" método. Todavía tirar error de acceso denegado. por ejemplo, mi raíz colección de sitios para mysite es " http://network.test.com ". el usuario quiere evaluar lista UserInformation esta colección de sitios. ¿Cómo puede acceder a eso?
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
{
ServerContext sc = ServerContext.Current;
UserProfileManager upm = new UserProfileManager(sc);
UserProfile up = null;
//get current user's profile (visitor)
if (upm.UserExists(SPContext.Current.Web.CurrentUser.LoginName))
{
up =upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
SPWeb web = SPContext.Current.Web;
SPList userInformationList = web.Lists["User Information List"];
Solución
carreras SPContext.Current
fuera de la RunWithelevatedPrivileges
elevado contexto. Para más información ver esta entrada del blog href="http://www.mikhaildikov.com/2007/07/runwithelevatedprivileges-watch-out-for.html".
Otros consejos
está configurando su SPWeb a SPContext.Current.Web, esto no habría privilegios elevados. Sólo SPWebs creados a partir de SPSites creados dentro del delegado son elevados.
Así que hay que reemplazar
SPWeb web = SPContext.Current.Web;
con
SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
está configurando su SPWeb a SPContext.Current.Web esto no tiene privilegios elevados. Consulte este poste :