HttpRequest.LogonUserIdentity Własność
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
WindowsIdentity Pobiera typ bieżącego użytkownika.
public:
property System::Security::Principal::WindowsIdentity ^ LogonUserIdentity { System::Security::Principal::WindowsIdentity ^ get(); };
public System.Security.Principal.WindowsIdentity LogonUserIdentity { get; }
member this.LogonUserIdentity : System.Security.Principal.WindowsIdentity
Public ReadOnly Property LogonUserIdentity As WindowsIdentity
Wartość nieruchomości
WindowsIdentity Obiekt dla bieżących ustawień uwierzytelniania Microsoft Internet Information Services (IIS).
Wyjątki
Aplikacja internetowa jest uruchomiona w trybie zintegrowanym usług IIS 7, a PostAuthenticateRequest zdarzenie nie zostało jeszcze podniesione.
Przykłady
Poniższy przykład kodu pokazuje, jak pobrać LogonUserIdentity właściwość bieżącego użytkownika i zapisać wartości każdego elementu w pliku tekstowym. Umieść ten kod na stronie ASP.NET, do których odwołuje się atrybut formularza ACTION .
<%@ Page Language="C#" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
/* NOTE: To use this sample, create a c:\temp folder,
* add the ASP.NET account (in IIS 5.x <machinename>\ASPNET,
* in IIS 6.x NETWORK SERVICE), and give it write permissions
* to the folder.*/
private const string INFO_DIR = @"c:\temp\";
private void Page_Load(object sender, System.EventArgs e)
{
// Validate that user is authenticated
if (!Request.LogonUserIdentity.IsAuthenticated)
Response.Redirect("LoginPage.aspx");
// Create a string that contains the file path
string strFilePath = INFO_DIR + "CS_Log.txt";
Response.Write("Writing log file to " + strFilePath + "...");
// Create stream writer object and pass it the file path
StreamWriter sw = File.CreateText(strFilePath);
// Write user info to log
sw.WriteLine("Access log from " + DateTime.Now.ToString());
sw.WriteLine("User: " + Request.LogonUserIdentity.User);
sw.WriteLine("Name: " + Request.LogonUserIdentity.Name);
sw.WriteLine("AuthenticationType: " + Request.LogonUserIdentity.AuthenticationType);
sw.WriteLine("ImpersonationLevel: " + Request.LogonUserIdentity.ImpersonationLevel);
sw.WriteLine("IsAnonymous: " + Request.LogonUserIdentity.IsAnonymous);
sw.WriteLine("IsGuest: " + Request.LogonUserIdentity.IsGuest);
sw.WriteLine("IsSystem: " + Request.LogonUserIdentity.IsSystem);
sw.WriteLine("Owner: " + Request.LogonUserIdentity.Owner);
sw.WriteLine("Token: " + Request.LogonUserIdentity.Token);
// Close the stream to the file.
sw.Close();
}
</script>
<%@ Page Language="VB" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
' * NOTE: To use this sample, create a c:\temp folder,
' * add the ASP.NET account (in IIS 5.x <machinename>\ASPNET,
' * in IIS 6.x NETWORK SERVICE), and give it write permissions
' * to the folder.
Private Const INFO_DIR As String = "c:\temp\"
Private Sub Page_Load(sender As Object, e As System.EventArgs)
' Validate that user is authenticated
If Not (Request.LogonUserIdentity.IsAuthenticated) Then
Response.Redirect("LoginPage.aspx")
End If
' Create a string that contains the file path
Dim strFilePath As String = INFO_DIR & "VB_Log.txt"
Response.Write("Writing log file to " & strFilePath & "...")
' Create stream writer object and pass it the file path
Dim sw As StreamWriter = File.CreateText(strFilePath)
' Write user info to log
sw.WriteLine("Access log from " & DateTime.Now.ToString())
sw.WriteLine("User: " & Request.LogonUserIdentity.User.ToString())
sw.WriteLine("Name: " & Request.LogonUserIdentity.Name)
sw.WriteLine("AuthenticationType: " & Request.LogonUserIdentity.AuthenticationType)
sw.WriteLine("ImpersonationLevel: " & Request.LogonUserIdentity.ImpersonationLevel)
sw.WriteLine("IsAnonymous: " & Request.LogonUserIdentity.IsAnonymous)
sw.WriteLine("IsGuest: " & Request.LogonUserIdentity.IsGuest)
sw.WriteLine("IsSystem: " & Request.LogonUserIdentity.IsSystem)
sw.WriteLine("Owner: " & Request.LogonUserIdentity.Owner.ToString())
sw.WriteLine("Token: " & Request.LogonUserIdentity.Token.ToString())
' Close the stream to the file.
sw.Close()
End Sub
</script>
Uwagi
Właściwość LogonUserIdentity uwidacznia właściwości i metody obiektu dla aktualnie połączonego WindowsIdentity użytkownika z Microsoft Internet Information Services (IIS). Wystąpienie WindowsIdentity klasy, która jest uwidoczniona przez LogonUserIdentity śledzi token żądania usług IIS i zapewnia łatwy dostęp do tego tokenu dla bieżącego żądania HTTP przetwarzanego wewnątrz ASP.NET. Wystąpienie WindowsIdentity klasy jest tworzone automatycznie, więc nie musi być skonstruowane w celu uzyskania dostępu do jego metod i właściwości.