TIPS-設定WCF使用Windows認證
原本測試OK的WCF,在取消IIS匿名存取,改用整合式驗證後出現以下錯誤訊息:
Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.
爬了一下文,大致的心得是要在web.config改變安全設定。原本的設定是VS2008建立AJAX enabled WCF時自動產生的:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebApiAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="WebApi">
<endpoint address="" behaviorConfiguration="WebApiAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApi"/>
</service>
</services>
</system.serviceModel>
要修改為:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="WebApiAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="WebApi">
<endpoint address="" behaviorConfiguration="WebApiAspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApi"
bindingConfiguration="NTLMBinding"
/>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="NTLMBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
醬就可以柳~~~ (羞昂風)