HttpRequest.LogonUserIdentity プロパティ
アセンブリ: System.Web (system.web.dll 内)

現在の Microsoft Internet Information Services (IIS) の認証設定に対応する WindowsIdentity。

LogonUserIdentity プロパティによって、Microsoft Internet Information Services (IIS) に現在接続しているユーザーの WindowsIdentity オブジェクトのプロパティとメソッドが公開されます。LogonUserIdentity によって公開される WindowsIdentity クラスのインスタンスは、IIS 要求のトークンを追跡し、ASP.NET の内部で処理されている現在の HTTP 要求に対するこのトークンに簡単にアクセスできるようにします。WindowsIdentity クラスのインスタンスは自動的に作成されるため、そのメソッドやプロパティにアクセスするために構築する必要はありません。

現在のユーザーの LogonUserIdentity プロパティを取得し、各項目の値をテキスト ファイルに出力する方法を次のコード例に示します。このコードは、フォームの ACTION 属性で参照されている ASP.NET ページ上に配置します。
<%@ 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>
<%@ 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>


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHttpRequest.LogonUserIdentity プロパティを検索する場合は、下記のリンクをクリックしてください。

- HttpRequest.LogonUserIdentity プロパティのページへのリンク