November Happy Hour will be moved to Thursday December 5th.

User permissions on a page

Vote:
 

Hi!

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??

/Jonas

#22730
Aug 13, 2008 16:32
Vote:
 

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <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";
                    else
      adminaccess.Text = "Admin mode access: No";
                    if (EPiServer.Security.PrincipalInfo.HasEditAccess)
                        editaccess.Text = "Edit mode access: Yes";
                    else
                        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();
                    rolesTable.Columns.Add("Name");
                    rolesTable.Columns.Add("ProviderName");
                    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;
                    GroupList.DataBind();
                }
                else
                    type.Text = "You are not authenticated";    
            }
         } 
  </script>
  </head>
  <body>
    <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">
        <Columns>
            <asp:BoundColumn DataField="Name" HeaderText="Group" />   
            <asp:BoundColumn DataField="ProviderName" HeaderText="Provider" />                       
        </Columns>
  </asp:DataGrid>
    </form>
  </body>
</html>



#22737
Edited, Aug 14, 2008 8:13
Vote:
 

Hi

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() );

...

#23329
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.