WindowsTokenRoleProvider.GetRolesForUser(String) Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Kullanıcının içinde olduğu Windows gruplarının listesini alır.
public:
override cli::array <System::String ^> ^ GetRolesForUser(System::String ^ username);
public override string[] GetRolesForUser (string username);
override this.GetRolesForUser : string -> string[]
Public Overrides Function GetRolesForUser (username As String) As String()
Parametreler
- username
- String
Windows gruplarının listesini ETKİ ALANI\kullanıcıadı biçiminde döndürecek kullanıcı.
Döndürülenler
Belirtilen kullanıcının içinde bulunduğu tüm Windows gruplarının adlarını içeren bir dize dizisi.
Özel durumlar
Şu anda yürütülen kullanıcının öğesine Usereklenmiş kimliği doğrulanmış WindowsIdentity bir kullanıcısı yok. HTTP olmayan senaryolarda, şu anda yürütülen kullanıcının öğesine CurrentPrincipaleklenmiş kimliği doğrulanmış WindowsIdentity bir kullanıcısı yoktur.
-veya-
username
geçerli WindowsIdentityile eşleşmiyorName.
-veya-
Kullanıcının Windows grup bilgileri alınırken bir hata oluştu.
username
, null
değeridir.
Güven düzeyi değerinden Lowküçüktür.
Örnekler
Aşağıdaki kod örneği, belirtilen kullanıcının rol listesini almak için yöntemini kullanır GetRolesForUser ve rol listesini bir GridView denetime bağlar. Rol yönetimini etkinleştiren bir Web.config dosyası örneği için bkz WindowsTokenRoleProvider. .
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
string[] rolesArray;
public void Page_Load()
{
Msg.Text = "";
try
{
if (!Roles.IsUserInRole(User.Identity.Name, @"BUILTIN\Administrators"))
{
Msg.Text = "You are not authorized to view user roles.";
return;
}
}
catch (HttpException e)
{
Msg.Text = "There is no current logged on user. Role membership cannot be verified.";
return;
}
// Bind roles to GridView.
rolesArray = Roles.GetRolesForUser(User.Identity.Name);
UserRolesGrid.DataSource = rolesArray;
UserRolesGrid.DataBind();
UserRolesGrid.Columns[0].HeaderText = "Roles for " + User.Identity.Name;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: View User Roles</title>
</head>
<body>
<form runat="server" id="PageForm">
<h3>View User Roles</h3>
<asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
<table border="0" cellspacing="4">
<tr>
<td valign="top"><asp:GridView runat="server" CellPadding="4" id="UserRolesGrid"
AutoGenerateColumns="false" Gridlines="None"
CellSpacing="0" >
<HeaderStyle BackColor="navy" ForeColor="white" />
<Columns>
<asp:TemplateField HeaderText="Roles" >
<ItemTemplate>
<%# Container.DataItem.ToString() %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView></td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Security" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim rolesArray() As String
Public Sub Page_Load()
Msg.Text = ""
Try
If Not Roles.IsUserInRole(User.Identity.Name, "BUILTIN\Administrators") Then
Msg.Text = "You are not authorized to view user roles."
Return
End If
Catch e As HttpException
Msg.Text = "There is no current logged on user. Role membership cannot be verified."
Return
End Try
' Bind roles to GridView.
rolesArray = Roles.GetRolesForUser(User.Identity.Name)
UserRolesGrid.DataSource = rolesArray
UserRolesGrid.DataBind()
UserRolesGrid.Columns(0).HeaderText = "Roles for " & User.Identity.Name
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: View User Roles</title>
</head>
<body>
<form runat="server" id="PageForm">
<h3>View User Roles</h3>
<asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />
<table border="0" cellspacing="4">
<tr>
<td valign="top"><asp:GridView runat="server" CellPadding="4" id="UserRolesGrid"
AutoGenerateColumns="false" Gridlines="None"
CellSpacing="0" >
<HeaderStyle BackColor="navy" ForeColor="white" />
<Columns>
<asp:TemplateField HeaderText="Roles" >
<ItemTemplate>
<%# Container.DataItem.ToString() %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView></td>
</tr>
</table>
</form>
</body>
</html>
Açıklamalar
Bu yöntem, belirtilen kullanıcının içinde olduğu Windows gruplarının bir listesini Windows işletim sisteminden almak için sınıfı tarafından Roles çağrılır. yöntemi GetRolesForUser , LOGON_USER sunucu değişkeni tarafından tanımlanarak yalnızca şu anda oturum açmış olan kullanıcı için çağrılabilir. parametresinde username
sağlanan değer şu anda oturum açmış olan kullanıcının adı değilse, bir System.Configuration.Provider.ProviderException oluşturulur.
ASP.NET ve Windows kimlik doğrulaması hakkında daha fazla bilgi için bkz. ASP.NET Kimlik Doğrulaması.