Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么LogonUser总是返回错误代码1008?_C#_Windows_Security_Winapi_Windows Authentication - Fatal编程技术网

C# 为什么LogonUser总是返回错误代码1008?

C# 为什么LogonUser总是返回错误代码1008?,c#,windows,security,winapi,windows-authentication,C#,Windows,Security,Winapi,Windows Authentication,我正在使用LogonUserA函数对运行在IIS7/Win2008上的ASP.NET 4.0 web应用程序中的用户进行身份验证。如果用户输入正确的用户名和密码,它会很好地工作,但如果用户名或密码错误,LogonUserA总是返回相同的错误代码1008,该错误代码转换为模糊的消息“试图引用不存在的令牌”。当然,如果LogonUserA失败,则将没有有效的令牌,那么此错误意味着什么?对于典型的登录错误是否有特定的错误代码?我怎样才能得到它 下面是我的代码: [DllImport("advapi32

我正在使用LogonUserA函数对运行在IIS7/Win2008上的ASP.NET 4.0 web应用程序中的用户进行身份验证。如果用户输入正确的用户名和密码,它会很好地工作,但如果用户名或密码错误,LogonUserA总是返回相同的错误代码1008,该错误代码转换为模糊的消息“试图引用不存在的令牌”。当然,如果LogonUserA失败,则将没有有效的令牌,那么此错误意味着什么?对于典型的登录错误是否有特定的错误代码?我怎样才能得到它

下面是我的代码:

[DllImport("advapi32.dll", SetLastError = true)]
public static extern int LogonUserA(string lpszUserName,
    string lpszDomain,
    string lpszPassword,
    int dwLogonType,
    int dwLogonProvider,
    ref IntPtr phToken);

if (0 != LogonUserA(userName, domain, newPassword, Logon32LogonInteractive, Logon32ProviderDefault, ref token))
{
    // error is always 1008 if user name of password is incorrect.
    int error = Marshal.GetLastWin32Error();

    var exception = new Win32Exception(error);

    // What I got in error log for above Win32Exception is:
    // System.ComponentModel.Win32Exception (0x80004005): An attempt was made to reference a token that does not exist
}

你找到解决这个问题的办法了吗?对不起,我还没有找到任何办法。