private bool CheckPrivilegeLevel() { // Gets the user object UserInfo user = MembershipContext.AuthenticatedUser; if (user != null) { // Checks whether the user has the Admin privilege level or higher if (user.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin, SiteContext.CurrentSiteName)) { // Perform an action according to the result return true; } } return false; }
在page load的时候,检查权限,如果没权限,就403终止
protected void Page_Load(object sender, EventArgs e) { bool flag = CheckPrivilegeLevel(); if (!flag) { Response.StatusCode = (int)System.Net.HttpStatusCode.Forbidden; Response.Flush(); Response.End(); } else { // Registers the default CSS and JavaScript files onto the page (used to style the UniGrid) CssRegistration.RegisterBootstrap(Page); ScriptHelper.RegisterBootstrapScripts(Page); MainGrid.DataSource = GetNoUseWebpartReplacement(); } }