使用kerberos连接到数据库

奥布·托布

我有以下问题:在我的客户,我称之为asp.net它连接到我的网站IISWCFActive Directory从客户端传递用户,然后从传递用户IIS,我尝试连接到SQL-Server(与相同的计算机上IIS)。
到这里为止一切正常!但是,当我尝试与AD用户建立与数据库的连接时,我得到了EntityCommandExecutionException

将请求发送到服务器时,发生了传输级错误。(提供者:共享内存提供程序,错误:0

有内部例外

没有提供所需的模拟级别,或者提供的模拟级别无效

我真的不知道如何处理此问题,或者不知道如何设置IISweb.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=&quot;data source=Server;initial catalog=Database;integrated security=False;User Id=user;password=password;multipleactiveresultsets=True;application name=EntityFramework&quot;" 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
        ...

    }
}
奥布·托布

终于我得到了它的工作。我只是忘记将模拟级别设置为Delegation因此,解决方案是在创建服务后在(client-)方法中设置模拟级别:

    var service = ServiceFunctions.GetService();

    if (service.ClientCredentials != null)
        service.ClientCredentials.Windows.AllowedImpersonationLevel =
                           TokenImpersonationLevel.Delegation;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章