2013-04-30 65 views
1

所以,我的问题与在生产服务器上的代码,运行Windows Server 2003 & IIS 6ASP.NET模拟不工作的生产

我试图模拟一个域帐户,它在本地工作正常。

虽然当它的功能模拟用户无法在服务器上,即返回false:

private bool impersonateValidUser(String userName, String domain, String password) 
    { 
     WindowsIdentity tempWindowsIdentity; 
     IntPtr token = IntPtr.Zero; 
     IntPtr tokenDuplicate = IntPtr.Zero; 

     if (RevertToSelf()) 
     { 
      if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0) 
      { 
       if (DuplicateToken(token, 2, ref tokenDuplicate) != 0) 
       { 
        tempWindowsIdentity = new WindowsIdentity(tokenDuplicate); 
        impersonationContext = tempWindowsIdentity.Impersonate(); 
        if (impersonationContext != null) 
        { 
         CloseHandle(token); 
         CloseHandle(tokenDuplicate); 
         return true; 
        } 
       } 
      } 
     } 
     if (token != IntPtr.Zero) 
      CloseHandle(token); 
     if (tokenDuplicate != IntPtr.Zero) 
      CloseHandle(tokenDuplicate); 
     return false; 
    } 

注意,代码不会崩溃 - 它只是返回false。有没有人经历过这个,并有什么我应该开始看什么想法?我假设IIS配置在这里,但可能需要几周才能找到导致此问题的小问题。

我可以使用我试图模拟在服务器上安装驱动器的帐户,以便帐户用户/密码组合很好,并且可以用于在Windows资源管理器中进行身份验证。

+0

请问哪个版本的IIS和Windows Server?请注意,您必须执行各种步骤才能进行委派,人们忘记做的最常见的事情就是允许服务器自己在Active Directory中委派“许可”。有关概览,请参阅http://support.microsoft.com/kb/810572。 – dash 2013-04-30 07:59:10

+0

2003&IIS 6 - 很好,我也会加入到这个问题中。 – 2013-04-30 08:00:38

+0

@dash该网站通常不会使用Windows模拟,因为它是外部面向的 - 但我使用它来执行一次身份验证,以从共享驱动器恢复文件。 – 2013-04-30 08:35:03

回答

1

我还记得,我在模仿不与集成模式下工作对于问题的解决方案项目同样的问题是,加入到我们的web.config:

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
</system.webServer> 

但与此impersonatig在Global.asax方法doesen't工作:

protected void Application_AuthenticateRequest(object sender, EventArgs e) 
protected void Application_BeginRequest(object sender, EventArgs e) 

希望这有助于你,因为我不知道哪个版本的ISS,这是。

+0

我的web.config中已经有了相同的设置,谢谢你的回答。 – 2013-04-30 08:33:46

+0

hm:/ this may help http://msdn.microsoft.com/en-us/library/134ec8tc%28v=vs.80%29.aspx – 2013-04-30 08:44:20