使用IIS和应用程序池进行WCF Windows身份验证

时间:2009-11-18 21:50:19

标签: windows wcf iis authentication application-pool

我使用具有自定义标识的应用程序池在IIS 6上运行WCF服务器

现在我在网上看了两天,我找不到问题的确切答案。我知道外面有很多类似的

在IIS6上,虚拟目录具有匿名访问禁​​用和启用集成Windows身份验证。服务帐户与计算机位于同一域中。我称之为svcE。我将svcE添加到IIS_WPG组。

现在,第一个问题是当我选择带有svcE的应用程序池来处理虚拟目录时,将其称为appDir,然后当我导航到appDir时,我会收到提示输入凭据但是如果我使用网络服务帐户我不会验证我以我的身份登录。

我想要做的是让服务在帐户svE下运行,因为它可以访问数据库,而无需将该信息放在WebConfig文件中。

我有配置文件

的网络服务
<authentication mode="Windows"/>

<bindings>
        <basicHttpBinding>
            <binding name="default">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows"/>
                </security>                  
            </binding>
        </basicHttpBinding>
    </bindings>

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="default" contract="<removed>">
 <identity>
  <dns value="localhost" />
 </identity>
</endpoint>   

使用该服务的Web配置

<basicHttpBinding>
            <!-- Create one Binding for all three services, save space-->
            <binding name="BasicHttpBinding_PricingService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows" proxyCredentialType="Windows"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>

        </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="<address>.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_PricingService"
            contract="<contract>" name="<name>" />

我试图实现的最终目的是

只有Windows经过身份验证的人才能拨打该服务 - &gt;然后,该服务使用serivce帐户与数据库进行所有交互。

请注意,如果我跳过第一部分并添加annon访问权限,那么它可以正常工作并将数据库称为

感谢您的帮助

4 个答案:

答案 0 :(得分:1)

如果您想将db调用作为特定帐户,您可以模拟该帐户的电话范围:

using ( WindowsImpersonationContext contexts = (new WindowsIdentity("account").Impersonate()){ db.MakeCall(); }

答案 1 :(得分:0)

当用户使用Windows身份验证连接时,您的服务似乎正在冒充用户。

当您使用匿名身份验证时,没有假冒因此没有问题。

当您使用Windows身份验证和domian帐户时,该帐户未被标记,因为它可以冒充这可能就是您获得登录的原因,默认情况下网络服务具有此权限。

尝试:

<authentication mode="Windows" impersonate="false"/>

答案 2 :(得分:0)

我遇到了同样的问题。

我需要访问c:\ inetpub \ wwwroot \文件夹。

我给了'DomainUsers'组读取权限。

答案 3 :(得分:0)

如果有人仍在努力解决此问题,您只需在web.config上模拟您的服务帐户:

<identity impersonate="true" userName="domain\svcname" password="password"/>
相关问题