Asp.net 用户登录失败';NT授权\\匿名登录';使用模拟从wcf服务访问sql server时

Asp.net 用户登录失败';NT授权\\匿名登录';使用模拟从wcf服务访问sql server时,asp.net,sql-server,wcf,wcf-security,Asp.net,Sql Server,Wcf,Wcf Security,我使用的WCF服务有一个非常具体的问题: 我有一个ASP.NET页面,其中包含两个下拉列表: 第一个是从ASP.NET代码中填充的 另一个是通过jqueryajax调用从WCF服务填充的 它们都使用模拟作为登录用户转到SQL Server数据库。 这对我们所有的客户都很有效,除了1个环境。 尝试从WCF服务调用数据库时出现以下异常: "Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'.","StackTrace":"

我使用的WCF服务有一个非常具体的问题:

我有一个ASP.NET页面,其中包含两个下拉列表:

  • 第一个是从ASP.NET代码中填充的
  • 另一个是通过jqueryajax调用从WCF服务填充的
它们都使用模拟作为登录用户转到SQL Server数据库。 这对我们所有的客户都很有效,除了1个环境。 尝试从WCF服务调用数据库时出现以下异常:

"Login failed for user 'NT AUTHORITY\\ANONYMOUS LOGON'.","StackTrace":"   
                at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)\u000d\u000a   
                at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)\u000d\u000a   
                at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)\u000d\u000a   
                at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)\u000d\u000a   
                at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)\u000d\u000a 
...
似乎出于某种原因,WCF服务正在使用匿名帐户访问数据库,尽管来自ASP.NET代码的调用仍按预期工作,并使用预期帐户访问数据库。 连接字符串使用
integratedsecurity=SSPI
。 这一定是我们缺少的某些特定于环境的配置,但我看不出委托和模拟直接从ASP.NET工作的确切方式

有人知道问题出在哪里吗

编辑: system.servicemodel部分:

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <bindings>
  <webHttpBinding>
    <binding name="ServiceWebBindingName">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows"></transport>
      </security>
    </binding>
  </webHttpBinding>     
</bindings>
<behaviors>
  <endpointBehaviors>     
    <behavior name="HistoryReportingEndpointBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="HistoryReportingServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceAuthorization principalPermissionMode="UseAspNetRoles" impersonateCallerForAllOperations="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
    <service behaviorConfiguration="HistoryReportingServiceBehavior" name="ServiceLibrary.HistoryReporting">
    <endpoint address="" behaviorConfiguration="HistoryReportingEndpointBehavior" binding="webHttpBinding" bindingConfiguration="ServiceWebBindingName" name="HistoryReportingWebEndPoint" contract="ServiceLibrary.IHistoryReporting" />
  </service>    
</services>
</system.serviceModel>


您收到的错误可能是因为您的web应用程序正在使用的IIS应用程序池运行的帐户不具有SQL Server权限。将应用程序池帐户更改为可以访问SQL Server的帐户,问题就会消失。

是否有原因不使用从WCF服务到SQL的显式SQL连接?它们是否在同一个框中?必须使用登录的Windows帐户进行连接。SQL server位于另一台计算机上。请确保WCF服务在具有SQL server权限的网络帐户下运行。或者,将用于运行WCF的Windows帐户添加到SQL Server上的登录中。现在,WCF正在NT\n下运行,因为这是您设置它的默认方式(我猜是在IIS下),但该帐户没有在另一台计算机上运行SQL的权限。因此,您需要将WCF运行的帐户更改为SQL可以接受的帐户。Windows帐户可以登录SQL Server,也可以从ASP.NET代码中使用。WCF服务和ASP.NET都在同一个项目中,所以不是在同一个用户帐户下运行吗?您只是将WCF作为可执行文件运行,还是它由IIS前置?我之所以这样做是因为NT\n是IIS运行web服务的默认ID。