如何从窗口登录凭证中单独获取用户ID

时间:2013-11-11 17:40:18

标签: c#

我正在尝试使用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

0 个答案:

没有答案