home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 24 aspnet applications / aspnetsecurity / protectedpage.aspx.vb < prev    next >
Encoding:
Text File  |  2002-03-18  |  2.4 KB  |  64 lines

  1. Imports System.Web.Security
  2. Imports System.Security.Principal
  3.  
  4. Public Class WebForm1
  5.     Inherits System.Web.UI.Page
  6.     Protected WithEvents lblUserInfo As System.Web.UI.WebControls.Label
  7.  
  8. #Region " Web Form Designer Generated Code "
  9.  
  10.     'This call is required by the Web Form Designer.
  11.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  12.  
  13.     End Sub
  14.  
  15.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  16.         'CODEGEN: This method call is required by the Web Form Designer
  17.         'Do not modify it using the code editor.
  18.         InitializeComponent()
  19.     End Sub
  20.  
  21. #End Region
  22.  
  23.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  24.         ' this code shows how you can learn the user identity
  25.  
  26.         ' retrieve user name and authentication method
  27.         Dim msg As String
  28.         If Not User.Identity.IsAuthenticated Then
  29.             msg = "Unauthenticated user"
  30.         Else
  31.             msg = "User name = " & User.Identity.Name & "<br />"
  32.             msg &= "Authentication type = " & User.Identity.AuthenticationType & "<br />"
  33.         End If
  34.  
  35.         ' this code retrieve additional information if user was
  36.         ' authenticated by using Windows authentication mode
  37.  
  38.         If User.Identity.IsAuthenticated And TypeOf User.Identity Is WindowsIdentity Then
  39.             Dim wi As WindowsIdentity = DirectCast(User.Identity, WindowsIdentity)
  40.             msg &= "Anonymous = " & wi.IsAnonymous & "<br />"
  41.             msg &= "Guest = " & wi.IsGuest & "<br />"
  42.             msg &= "System = " & wi.IsSystem & "<br />"
  43.  
  44.             Dim wp As WindowsPrincipal = DirectCast(User, WindowsPrincipal)
  45.             If wp.IsInRole(WindowsBuiltInRole.Guest) Then
  46.  
  47.             End If
  48.         End If
  49.  
  50.         ' display other information about the current ASP.NET process
  51.  
  52.         Dim pi As ProcessInfo = ProcessModelInfo.GetCurrentProcessInfo
  53.         msg &= "ProcessID = " & pi.ProcessID.ToString & "<br />"
  54.         msg &= "Status = " & pi.Status.ToString & "<br />"
  55.         msg &= "StartTime = " & pi.StartTime & "<br />"
  56.         msg &= "Age = " & pi.Age.ToString & "<br />"
  57.         msg &= "RequestCount = " & pi.RequestCount & "<br />"
  58.         msg &= "PeakMemoryUsed = " & pi.PeakMemoryUsed.ToString & "<br />"
  59.         lblUserInfo.Text = msg
  60.  
  61.     End Sub
  62.  
  63. End Class
  64.