无法使用从IIS7托pipe的ASP.Net Web应用程序的Win Auth连接到数据库

我有一个在Windows Server 2008 64位与IIS 7和SQL Server 2008托pipe的Web应用程序。Web应用程序池帐户是networking服务,我已经将此帐户添加到SQL Server 2008login并映射到用户在数据库中与dbowner权限。

这个网站是在ASP.Net 2.0,它使用表单身份validation,以确保其资源(不是全部)的访问,所以匿名访问,Imersonation = True和表单身份validation在IIS 7中启用。Web应用程序正在使用成员资格提供程序控件。

网站启动时 在“应用程序启动”中,它尝试连接到数据库并读取一些启动configuration。 数据库的连接string保存在web.config中。 以下是连接string。

Data Source=XXXXX; Initial Catalog=XXXXX; Integrated Security=SSPI; Trusted_Connection=True; 

但是,当应用程序启动失败,连接到数据库,我发现事件日志中的以下3个条目。

与集成安全性build立连接时,SSPI握手失败,错误代码为0x8009030c; 连接已closures。 [客户:]


login失败。 login来自不受信任的域,不能与Windows身份validation一起使用。 [客户:]


 Event code: 3005 Event message: An unhandled exception has occurred. Event time: 4/26/2011 9:22:05 PM Event time (UTC): 4/26/2011 6:22:05 PM Event ID: 71a4b2cd8d40492ab89af3430cf42ea5 Event sequence: 2 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/5/ROOT-1-129483157247676684 Trust level: Full Application Virtual Path: / Application Path: C:\LMS Projects\Deployment\Web Applications\Microsoft Dynamics CRM Customer LMS Portal\ Machine name: LMS Process information: Process ID: 3688 Process name: w3wp.exe Account name: NT AUTHORITY\NETWORK SERVICE Exception information: Exception type: LoyaltyException Exception message: Exception of type 'LMS.Helpers.LoyaltyException' was thrown. Request information: Request URL: http://localhost:6666/default.aspx Request path: /default.aspx User host address: ::1 User: Is authenticated: False Authentication Type: Thread account name: NT AUTHORITY\NETWORK SERVICE Thread information: Thread ID: 4 Thread account name: NT AUTHORITY\NETWORK SERVICE Is impersonating: False Stack trace: at ASP.global_asax.Application_Start() in c:\LMS Projects\Deployment\Web Applications\Microsoft Dynamics CRM Customer LMS Portal\Global.asax:line 27 

上面显示的exception是我在处理平台exception后抛出的自定义exception,所以不会被误认为是代码中的错误。 此代码在Windows Server 2003和IIS 6.0环境中正常工作。

模仿会导致您的匿名用户被使用,而不是您的应用程序池用户。

这里有几个build议:

  • 如果您为每个网站设置了自己的应用程序池,则匿名用户将其设置为使用应用程序池用户。 那么你只需要维护一个用户。
  • 将您的应用程序池用户设置为networking服务以外的其他用户 由于您使用的是IIS 7.0(WS08 RTM),因此使用IIS APPPOOL \ AppPoolName用户更加困难,而且通常不能直接使用NETWORK SERVICE。 有一些已知的权限安全漏洞的提升,并授予该帐户的权限也为其他应用程序打开。 我可能只是创build一个自定义用户,分配给应用程序池,授予磁盘的权限,然后授予访问数据库。