Try our conversational search powered by Generative AI!

User permissions on a page



What's the best way to check what permissions a user (Windows user) has on a page?

QueryDistinctAccess, only give me permissions that are defined on the page, not permissions given though group memberships??


Aug 13, 2008 16:32

Hi Jonas

Could give this aspx a try.

<%@ Page language="c#" AutoEventWireup="True" Inherits="System.Web.UI.Page"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
  <head id="Head1" runat="server">
    <title>Test page for information about the current user</title>
  <script runat="server">
      public void Page_Load(System.Object sender, System.EventArgs e)
            if (!IsPostBack)
                if (EPiServer.Security.PrincipalInfo.CurrentPrincipal.Identity.IsAuthenticated)
                    type.Text = "Your authentication type is: " + EPiServer.Security.PrincipalInfo.Current.Principal.Identity.AuthenticationType;
                    System.Web.Security.MembershipUser CurrentUser = System.Web.Security.Membership.GetUser(EPiServer.Security.PrincipalInfo.Current.Name);
                    username.Text = "You are authenticated as: " + CurrentUser.UserName;
                    userprovider.Text = "You are logged with: " + CurrentUser.ProviderName;
                    if (EPiServer.Security.PrincipalInfo.HasAdminAccess)
      adminaccess.Text = "Admin mode access: Yes";
      adminaccess.Text = "Admin mode access: No";
                    if (EPiServer.Security.PrincipalInfo.HasEditAccess)
                        editaccess.Text = "Edit mode access: Yes";
                        editaccess.Text = "Edit mode access: No";
                   System.Collections.Generic.IList<EPiServer.Security.RoleItem> allRoles = EPiServer.Security.RoleProviderUtility.GetAllRolesWithProviders();              
                    System.Data.DataTable rolesTable = new System.Data.DataTable();
                    foreach (EPiServer.Security.RoleItem role in allRoles)
                         if (EPiServer.Security.PrincipalInfo.Current.Principal.IsInRole(role.RoleName))
                             rolesTable.Rows.Add(new System.Object[] { role.RoleName, role.ProviderName });
                    GroupList.DataSource = rolesTable;
                    type.Text = "You are not authenticated";    
    <form id="Form1" method="post" runat="server">
  <asp:label Runat="server" id="type" /><br />
        <asp:label Runat="server" id="username" /><br />
        <asp:label Runat="server" id="userprovider" /><br />
  <asp:label Runat="server" id="adminaccess" /><br />
  <asp:label Runat="server" id="editaccess" /><br />    
        <asp:DataGrid ID="GroupList" AutoGenerateColumns="False" runat="server">
            <asp:BoundColumn DataField="Name" HeaderText="Group" />   
            <asp:BoundColumn DataField="ProviderName" HeaderText="Provider" />                       

Edited, Aug 14, 2008 8:13


I had a similar problem where I wanted to send a Authenticated user-id to one external forms. You can also try this out.


Response.Write( EPiServer.Security.UnifiedPrincipal.Current.Identity.Name.ToString() + ", " + EPiServer.Security.UnifiedPrincipal.Current.GroupList[0].ToString() + ", " + EPiServer.Security.UnifiedPrincipal.Current.GroupList[1].ToString() + ", " + EPiServer.Security.UnifiedPrincipal.Current.GroupList[2].ToString() );


Edited, Sep 03, 2008 15:19
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.