C# 基于IIS 7.5的REST-IIS指定的身份验证方案异常

C# 基于IIS 7.5的REST-IIS指定的身份验证方案异常,c#,wcf,rest,C#,Wcf,Rest,首先,该服务在使用IIS 7.5的Server 2008环境中正常工作。Windows 7/IIS 7.5环境中的同一服务显示以下错误: [InvalidOperationException: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authenticat

首先,该服务在使用IIS 7.5的Server 2008环境中正常工作。Windows 7/IIS 7.5环境中的同一服务显示以下错误:

[InvalidOperationException: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.]
   System.ServiceModel.Web.WebServiceHost.SetBindingCredentialBasedOnHostedEnvironment(ServiceEndpoint serviceEndpoint, AuthenticationSchemes supportedSchemes) +349683
   System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host, IDictionary`2 implementedContracts, String multipleContractsErrorMessage, String standardEndpointKind) +806
   System.ServiceModel.Web.WebServiceHost.OnOpening() +244
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +274
   System.ServiceModel.Channels.CommunicationObject.Open() +36
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +184
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/IMonSapService' cannot be activated due to an exception during compilation.  The exception message is: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +687598
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +96
我的Global.asax.cs中有以下行

RouteTable.Routes.Add(new ServiceRoute("IMonSapService", new WebServiceHostFactory(),
                    typeof(IMonSapService)));
这里是服务实现的第一行

[AspNetCompatibilityRequirements
    (RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class IMonSapService : IIMonSapService
{
...
}
我的web.config如下所示

 <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <httpRuntime />
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>

我比较了两个IIS实例,但没有发现差异。

在applicationHost.config中找到了这一点

<authentication>
    <anonymousAuthentication enabled="true" userName="IUSR"/>
    <basicAuthentication enabled="false"/>
    <clientCertificateMappingAuthentication/>
    <digestAuthentication/>
    <iisClientCertificateMappingAuthentication/>
    <windowsAuthentication enabled="true"/>
</authentication>
将Windows身份验证更改为

    <windowsAuthentication enabled="false"/>

解决了这个问题。我认为在IIS管理器/身份验证中,所有内容都已禁用,但我必须在配置文件中对此进行更改。

请添加windows2008和windows7上激活和安装的身份验证的屏幕截图。