Loading...

Monday, September 19, 2011

OOB authorization with SPSecurityTrimmedControl

Using In Webparts
1)Declare SPSecurityTrimmedControl
SPSecurityTrimmedControl stcEditItem = new SPSecurityTrimmedControl();


2)Define Controls in WebPart
protected override void CreateChildControls()

{

stcEditItem.ID = "idPrm";

stcEditItem.Permissions = SPBasePermissions.ManageWeb;

ltrPopup.ID = "ltrPerm";

stcEditItem.Controls.Add(ltrPopup);

this.Controls.Add(stcEditItem);
}
3)Render the Trimmed Html contents,Now these content are available to administrators only


protected override void Render(HtmlTextWriter writer)

{

StringBuilder sb = AddModalPopUp(SPContext.Current.Web);

ltrPopup.Text = sb.ToString();

stcEditItem.RenderControl(writer);

}
Using in Visual Webpart
Open the .ascx file and add the controls inside SPSecurityTrimmedControl
SharePoint:SPSecurityTrimmedControl ID="ctrlSecurityTrimmed" runat="server" Permissions="ManageWeb">
controls. here..
SharePoint:SPSecurityTrimmedControl>

No comments: