Imports System.Security.Principal Imports System.Web.Security Public Class XMLFormsAuthentication Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents Label3 As System.Web.UI.WebControls.Label Protected WithEvents Label2 As System.Web.UI.WebControls.Label Protected WithEvents Label4 As System.Web.UI.WebControls.Label Protected WithEvents Label5 As System.Web.UI.WebControls.Label Protected WithEvents IMG1 As System.Web.UI.HtmlControls.HtmlImage Protected WithEvents IMG2 As System.Web.UI.HtmlControls.HtmlImage Protected WithEvents LogOff As System.Web.UI.HtmlControls.HtmlInputButton 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack Then Dim WinID As WindowsIdentity WinID = WindowsIdentity.GetCurrent Label2.Text = "Welcome : " & WinID.Name & " " & Context.User.Identity.Name Dim MyPos As Integer MyPos = InStr(1, WinID.Name, "ASPNET") If MyPos > 0 Then Label3.Text = "The application is using the ASPNET Account." Else Label3.Text = "The application is not using the ASPNET Account." End If If (WinID.IsAuthenticated.ToString() = "True") Then Label4.Text = "You have been authenticated using Windows." Else Label4.Text = "You have not been authenticated." End If If WinID.AuthenticationType.ToString = "NTLM" Then Label1.Text = "Windows Account Information" Else Label1.Text = "Authentication Information" End If Dim wp As New WindowsPrincipal(WinID) Dim UserRoles As String = "Built-in role : " If wp.IsInRole(WindowsBuiltInRole.Administrator) Then UserRoles += "Administrator" ElseIf wp.IsInRole(WindowsBuiltInRole.PowerUser) Then UserRoles += "Power User" ElseIf wp.IsInRole(WindowsBuiltInRole.Guest) Then UserRoles += "Guest" ElseIf wp.IsInRole(WindowsBuiltInRole.User) Then UserRoles += "User" ElseIf wp.IsInRole(551) Then UserRoles += "Backup Operator" ElseIf wp.IsInRole(550) Then UserRoles += "Print Operator" Else UserRoles = "Unknown" End If Label5.Text = UserRoles End If End Sub Private Sub LogOff_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogOff.ServerClick FormsAuthentication.SignOut() Response.Redirect("XMLLogin.aspx") End Sub End Class