1

IIS でホストされ、 MyComputer\MyAdminUser Windows ユーザー (管理者権限を持つ)の下で実行される ASP.NET Core 2.2 Web アプリケーションがあります。私たちのアプリケーション f.ex で作業している現在の Windows ユーザーの名前を取得する必要があります。MyComputer\MyClientUser . すべてのクライアント ユーザーはローカル ユーザー ( MyComputer\ ... ) です。どうすればいいですか?

私はさまざまなアプローチを使用しようとしましたが、誰も期待した結果をもたらしません ( MyClientUser ):

1. HttpContext.Current.Request.LogonUserIdentity;

'HttpContext' には ' ' の定義が含まれておらずCurrent、タイプ 'HttpContext' の最初の引数を受け入れるアクセス可能な拡張メソッド 'Current' が見つかりませんでした...

2. Request.LogonUserIdentity;

と同じ問題LogonUserIdentity

3. Request.ServerVariables["LOGON_USER"];

と同じ問題ServerVariables

4. Request.Headers

このリストには、現在の Windows ユーザーに関する情報は含まれていません

5. Environment.UserName

結果は「MyAdminUser」です

6. WindowsIdentity.GetCurrent().Name

結果は「MyComputer\MyAdminUser」です

7. ManagementObjectCollection collection = 
      new ManagementObjectSearcher("SELECT UserName FROM Win32_ComputerSystem")
      .Get();
   collection?.Cast<ManagementBaseObject>()?.First()?.Properties?["UserName"]?.Value

Visual Studio の結果は正しい (現在の Windows ユーザー) ですが、IIS ではProperties?["UserName"]?.Valuenull または空 ( Properties?["UserName"]?.Name= "UserName")です。

私は何を間違っていますか?どうすれば期待される名前を取得できますか?

4

0 に答える 0