사용자가 특정 리소스에 액세스하고 웹 파트 렌더링 렌더링을 중지 할 수있는 권한이없는 경우 처리 할 수 있습니다. 당신이 웹 파트의 CreateChildControls
의 리소스에 액세스하는 가정 :
private bool accessDenied;
protected override void CreateChildControls()
{
try
{
// prevent SharePoint from catching an access denied exception and
// redirecting to the error page.
using (new SPSecurity.SuppressAccessDeniedRedirectInScope())
{
SPContext.Current.Web.Lists["Restriced"] // some thing...
}
}
catch (UnauthorizedAccessException)
{
// set variable in case the user has not enough permissions
accessDenied = true;
}
}
지금, 우리는 사용자가 리소스에 액세스 할 수있는 충분한 권한을하지 있는지 여부를 알 수
첫째, 액세스 처리 부인했다. 다음 단계는 렌더링을 비활성화하고 웹 파트와 그 내용을 숨기는 것입니다. 웹 파트를 숨기는 것은 간단합니다.
protected override void RenderWebPart(HtmlTextWriter writer)
{
if (accessDenied) return;
base.RenderWebPart(writer);
}
대신 오류 메시지를 표시 할 수 있습니다. 그러나 이것은 목적을 무너 뜨릴 것입니다.
마지막 단계는 웹 파트의 크롬을 비활성화하는 것입니다. 이것은 OnPreRender
방법에 ChromeType
를 설정하여 수행 할 수 있습니다 물론
protected override void OnPreRender(EventArgs e)
{
// Important to call base method in order to ensure child controls...
base.OnPreRender(e);
if (accessDenied)
{
ChromeType = PartChromeType.None;
}
}
, 당신은 당신이 accessDenied
가 설정되어 있는지 확인해야 웹 파트에서 다른 방법을 재정의합니다.