我正在尝试使用 C# 代码获取用户 ID,如下所示:
string username = System.Web.HttpContext.Current.User.Identity.Name;
我得到这样的用户名和凭据
用户名:“ACSIND\11111111”
这里的用户 ID 是 '11111111'
但我无法从代码中单独获取用户 ID。
我在 VB 中完成了如下操作:
Option Compare Database
Option Explicit
Private Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetCurrentUserName() As String
On Error GoTo Err_GetCurrentUserName
Dim lpBuff As String * 25
Dim ret As Long, Username As String
ret = GetUserName(lpBuff, 25)
Username = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
GetCurrentUserName = Username & ""
Exit_GetCurrentUserName:
Exit Function
Err_GetCurrentUserName:
MsgBox Err.Description
Resume Exit_GetCurrentUserName
End Function
请帮助如何在 C# 中单独获取 userId