【发布时间】:2014-08-15 13:31:53
【问题描述】:
我有以下问题:
在我的客户端上,我调用了一个asp.net 站点,该站点使用WCF 连接到我的IIS。我从客户端传递我的Active Directory 用户,然后从IIS 传递,我尝试连接到SQL-Server(与IIS 在同一台机器上)。
直到这里一切正常!但是当我尝试使用 AD 用户连接到数据库时,我得到一个EntityCommandExecutionException:
向服务器发送请求时发生传输级错误。 (提供者:共享内存提供者,错误:0
内部异常
没有提供所需的模拟级别,或者提供的模拟级别无效
我真的不知道如何处理这个或在IIS 或一些web.config 中设置什么
将此用户传递给数据库。
也许有人知道如何解决这个特定问题?
编辑:
这是 WCF 客户端的 Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<customErrors mode="Off"/>
<identity impersonate="true"/>
<authentication mode="Windows" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<system.serviceModel>
<bindings>
<ws2007HttpBinding>
<binding name="ws2007Binding" closeTimeout="00:10:00" sendTimeout="00:10:00"
transactionFlow="false" >
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<client>
<endpoint address="http://server/service/Service.svc"
binding="ws2007HttpBinding" bindingConfiguration="" contract="Service.IService"
name="ws2007HttpBinding_IService">
<identity>
<servicePrincipalName value="MSSQLsvc/server:1433" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
这个是针对 WCF 服务的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<ws2007HttpBinding>
<binding name="ws2007Binding" closeTimeout="00:10:00" sendTimeout="00:10:00"
transactionFlow="false" >
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true"/>
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<protocolMapping>
<add binding="ws2007HttpBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
<connectionStrings>
<add name="Entities" connectionString="metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;provider=System.Data.SqlClient;provider connection string="data source=Server;initial catalog=Database;integrated security=False;User Id=user;password=password;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
现在我使用Web.Config 中的用户访问数据库一次,一切正常,但是当我尝试委派我的 AD 用户然后连接到数据库时,我得到一个异常:
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public List<string> GetInfo(string text)
{
using (var db = new Entities())
{
var someTempInfos = db.Infos.Find(text); //<-- EntityCommandExecutionException
...
}
}
【问题讨论】:
-
你能添加一些示例代码来说明你在做什么吗?您很可能在此处遇到 Kerberos 约束委派问题和/或主机上的权限。
-
@BrianDesmond 我更新了我的问题,希望现在更清楚一点。
标签: asp.net wcf active-directory kerberos