![](/img/trans.png)
[英]WebPart that redirect if user is not in a specific SharePoint security group
[英]Sharepoint Webpart Security Exception
我有一個自定義共享點Web部件,該部件拋出以下異常:
System.Security.SecurityException: Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed.
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at Waverly.SharePoint.Features.WebParts.SearchesListWebPart.Render(HtmlTextWriter writer)
The action that failed was:
Demand
The type of the first permission that failed was:
Microsoft.SharePoint.Security.SharePointPermission
The Zone of the assembly that failed was:
MyComputer
我的理論是,Sharepoint沒有運行Web部件的信任級別,但是我很難弄清楚如何調試此問題。 任何人都有調試此類內容的經驗嗎?
您有幾種選擇。 首先是將程序集安裝到GAC中。 然后它將獲得完全的信任,但是您必須將其安裝在GAC中,使用強名稱命名,等等。第二個選項是進入web.config並將其添加到受信任列表中。 本文和這篇 文章將幫助您走這條路。
第三個選項是將程序集放置在C:\\ inetpub \\ wwwroot \\ wss \\ VirtualDirectories [port] _app_bin文件夾中。 這是在全局SharePoint配置中設置的,以完全信任其中的所有程序集。 您可能想先嘗試一下,看看是否有幫助,如果有,請使用其他兩種方法中的一種(因為從技術上講,這是一個未記錄的功能,可以更改)
編輯:好的,您可以嘗試一些方法。 如本文所示,嘗試提高總體信任級別。 基本上尋找:
<trust level =“ Full” originUrl =“” />
如果可行,則表明您所依賴的DLL是不受信任的。 請注意,您不想將其信任級別設置為Full,因為這意味着任何Webpart都具有完全信任。
有幫助嗎?
太瘋狂了 我無法在Web部件中執行以下行:
using (SPSite site = new SPSite(parentWebUrl))
但是我可以不使用Web部件執行它。
盡管DLL在GAC中,並且添加到了安全控件中,但它引發了一個類似的異常。
Exception: SecurityException
Message: Request failed.
Action: System.Security.Permissions.SecurityAction.Demand
Some stack trace:
at Microsoft.SharePoint.SPWeb.SPWebConstructor(SPSite site, String url, Boolean bExactWebUrl, SPRequest request)
at Microsoft.SharePoint.SPWeb..ctor(SPSite site, String url, Boolean bExactWebUrl)
at Microsoft.SharePoint.SPSite.OpenWeb()
at ....
它還說
((System.Security.SecurityException)($exception)).Demanded
((System.Security.SecurityException)($exception)).DenySetInstance
((System.Security.SecurityException)($exception)).FailedAssemblyInfo
((System.Security.SecurityException)($exception)).FirstPermissionThatFailed
((System.Security.SecurityException)($exception)).GrantedSet
引發了異常。
這是什么問題?
事實證明,由於webpart構造函數中發生了各種動作,因此經常發生諸如thse之類的錯誤。 您幾乎無法在那里與SharePoint對象模型進行交互。
將代碼移到其他地方,它可能會起作用。 我將代碼移至CreateChildControls並成功。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.