i have a project where i need to use the active directory for login to a website made in asp.net, i follow this tutorial….
Active Directory Authentication from ASP .NET
now i want to get the groups of the user, i tried the next code in the default.aspx.vb page but doesn’t work..
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write("Hello, " + Server.HtmlEncode(User.Identity.Name))
Dim id As FormsIdentity = CType(User.Identity, FormsIdentity)
If id IsNot Nothing Then
Dim ticket As FormsAuthenticationTicket = id.Ticket
Response.Write("<p/>TicketName: " + ticket.Name)
Response.Write("<br/>Cookie Path: " + ticket.CookiePath)
Response.Write("<br/>Ticket Expiration: " + ticket.Expiration.ToString())
Response.Write("<br/>Expired: " + ticket.Expired.ToString())
Response.Write("<br/>Persistent: " + ticket.IsPersistent.ToString())
Response.Write("<br/>IssueDate: " + ticket.IssueDate.ToString())
Response.Write("<br/>UserData: " + ticket.UserData)
Response.Write("<br/>Version: " + ticket.Version.ToString())
End If
End Sub
I find a better solution, is more easy than any answer that i find on the internet.
First i create a class to validate if an user is in a group in the active directory:
Region “Groups Verification”
End Region
Then you have to create a function in the code behind of all pages:
And to finish to have to use the function in the Page_load event: