RunwithelevatedPrivilegesを使用する場合、アクセスが拒否されましたか?

StackOverflow https://stackoverflow.com/questions/3049393

  •  27-09-2019
  •  | 
  •  

質問

通常のユーザーがMySite Rootサイトの「ユーザー情報リスト」にアクセスできるようにしたいと思います。 「RunWitheveatedPrivileges」メソッドを使用しています。まだアクセスを拒否されたエラーをスローします。たとえば、MySiteの私のルートサイトコレクションは「http://network.test.com"。ユーザーは、このサイトコレクションをuserinformationリストを評価したいのです。どのようにアクセスできますか?

 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"];
役に立ちましたか?

解決

SPContext.Current 外で走ります RunWithelevatedPrivileges 上昇したコンテキスト。詳細については、参照してください これ ブログ投稿。

他のヒント

spwebをspcontext.current.webに設定していますが、これには特権が向上していません。デリゲート内で作成されたSPSITESから作成されたSPWEBのみが昇格します。

したがって、交換する必要があります

SPWeb web = SPContext.Current.Web;

SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);

spwebをspcontext.current.webに設定しています。これには特権が向上していません。これを参照してください 役職:

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top