blog.icewolf.ch

Let's talk about IT!
posts - 1799, comments - 295, trackbacks - 0

My Links

Archives

Post Categories

icewolf

ASP.Net Get Group Membership from Windows Authenticated User

Hallo zusammen,

Heute wurde ich gefragt, ob es denn aus einer ASP.Net Applikation heraus möglich ist, die Active Directory Gruppenmitgliedschaft eines Users auszulesen, welcher sich auf einer Website anmeldet.

Klar - das ist ganz einfach. Im IIS Auf der Website nur Windows Authentification aktivieren.

web.config

<system.web>
 <authentication mode="Windows" />
</system.web>

default.aspx

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Import Namespace="System.Collections" %>

<script runat="server">
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim groups As New ArrayList()
        Dim group As System.Security.Principal.IdentityReference

        For Each group In System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups
            groups.Add(group.Translate(GetType(System.Security.Principal.NTAccount)).ToString())
            Response.Write("Group: " & group.Translate(GetType(System.Security.Principal.NTAccount)).ToString() & "<BR>")

        Next

        If groups.Contains("CORP\G-TestCorpIcewolfCH") Then
            lblGroupMember.Text = "User is in that Group"
        End If
  
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Get AD Group Membership</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:Label ID="lblGroupMember" runat="server" Text="Label"></asp:Label>
    </form>
</body>
</html>

Grüsse
Andres Bohren

Print | posted on Thursday, September 2, 2010 10:21 PM | Filed Under [ Web ]

Powered by:
Powered By Subtext Powered By ASP.NET