繁体   English   中英

出现403禁止错误。 客户端身份验证方案“匿名”禁止HTTP请求

[英]Getting 403 Forbidden error. The HTTP request was forbidden with client authentication scheme 'Anonymous'

我遇到的这个问题并未在所有访问我们服务的客户端上发生,但是一致的是,当确实发生错误时,它在少数客户端的同一服务调用上发生。

以下是例外的详细信息:

System.ServiceModel.Security.MessageSecurityException客户端身份验证方案“匿名”禁止了HTTP请求。 System.ServiceModel.Security.MessageSecurityException:客户端身份验证方案“匿名”禁止使用HTTP请求。 > ---> System.Net.WebException:远程服务器返回错误:(403)禁止。 在System.Net.HttpWebRequest.GetResponse()在System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)-内部异常堆栈跟踪结束-服务器堆栈跟踪:在System.ServiceModel.Security .IssuanceTokenProviderBase 1.DoNegotiation(TimeSpan timeout) at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.TlsnegoTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout) at System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider, TimeSpan timeout) at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory 1.DoNegotiation(TimeSpan timeout) at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.TlsnegoTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout) at System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider, TimeSpan timeout) at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory 1.ClientSecurityChannel 1.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout) at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionClientSettings .System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)处的System.ServiceModel.Channels.Services.Service.OnOpen(TimeSpan处1.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout) at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionClientSettings ClientSecuritySessionChannel.OnOpen(TimeSpan超时)超时)
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)处System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel通道,TimeSpan超时)处于System.ServiceModel.Channels处。 System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan超时)在System.ServiceModel.Channels.ServiceChannel.Call处的ServiceChannel.CallOnceManager.CallOnce(TimeSpan超时,CallOnceManager级联)(字符串操作,布尔型单向,ProxyOperationRuntime操作,Object [] ins ,在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs)在System.ServiceModel.Channels.ServiceChannel.Call(System.ServiceModel.Channels.ServiceChannelProxy.InvokeService( System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)上的IMethodCallMessage方法调用,ProxyOperationRuntime操作(IMessage消息)在[0]处引发了异常:System.Runtime.Remoting.Pr Proxy.FileTransferService.IFileTransferService.EstablishProxy( DownloadRequest请求)上的oxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)位于System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型) 。 LoggingFileTransferServiceClient.Download(Int32 packageId,ISt)上的NormalFileTransferServiceClient.Download(Int32 packageId,IStreamWriter下载器,存档器存档器)上的Proxy.FileTransferService.IFileTransferService.EstablishProxy(DownloadRequest请求)

客户端会抛出该异常。

IFileTransferService的客户端代理配置为:

<binding name="WSHttpBinding_IFileTransferService" closeTimeout="00:01:00"
  openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
  bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
  maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom"
  textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
  <reliableSession ordered="true" inactivityTimeout="00:10:00"
    enabled="false" />
  <security mode="Message">
    <transport clientCredentialType="Windows" proxyCredentialType="None"
      realm="" />
    <message clientCredentialType="UserName" negotiateServiceCredential="true"
      algorithmSuite="Default" establishSecurityContext="true" />
  </security>
</binding>

  <endpoint address="http://[hostname]/FileTransferService.svc/FileTransfer"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFileTransferService"
    contract="Proxy.FileTransferService.IFileTransferService"
    name="WSHttpBinding_IFileTransferService">
    <identity>
      <certificate encodedValue="a long string"/>
    </identity>
  </endpoint>

服务配置是

<service behaviorConfiguration="ServiceBehavior" 
    name="Services.FileTransferService">
        <endpoint name="WSHttpBinding_IFileTransferService" 
       binding="wsHttpBinding" 
       bindingConfiguration="MtomWSHttpBinding" 
       contract="Services.IFileTransferService" 
       address="/FileTransfer"/>
        <endpoint binding="basicHttpBinding" 
       bindingConfiguration="FileTransferServicesBinding" 
       contract="Services.IFileTransferService"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://[hostname]/FileTransferService.svc"/>
          </baseAddresses>
        </host>
</service>

<binding name="wsHttpBinding" 
         maxReceivedMessageSize="2147483647" 
         receiveTimeout="5" 
         useDefaultWebProxy="false">
      <readerQuotas maxDepth="2147483647" 
             maxStringContentLength="2147483647" 
             maxArrayLength="2147483647" 
             maxBytesPerRead="2147483647" 
             maxNameTableCharCount="2147483647" />
  <security mode="Message">
    <message clientCredentialType="UserName" />
  </security>
</binding>

<basicHttpBinding>
    <binding name="FileTransferServicesBinding" 
           maxReceivedMessageSize="10067108864" 
           messageEncoding="Mtom" 
           transferMode="Streamed" 
           useDefaultWebProxy="false">
      <security mode="None">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>

注意:一些客户端正在使用basicHttpBinding(如果我正确设置了所有内容)。 在客户端的更高版本中(可能尚未完全分发)(这就是为什么我必须支持2版本),我将代理更改为使用wsHttpBinding端点。 我想知道我收到的此错误是否特定于basicHttp,如果是,也许我没有正确设置这些配置。 我假设正在收到此403错误的客户端正在使用wsHttpBinding。

这是该服务的代码:

public RemoteBinaryInfo EstablishProxy(DownloadRequest request)
{
    int packageId = request.PackageId;

    System.IO.MemoryStream stream = new System.IO.MemoryStream(packageRepository.GetPackageBinary(packageId));

    DisposeStreamWhenOperationIsComplete(stream, OperationContext.Current);

    RemoteBinaryInfo result = new RemoteBinaryInfo();
    result.Length = stream.Length;
    result.MemoryByteStream = stream;
    return result;

}

private static void DisposeStreamWhenOperationIsComplete(System.IO.MemoryStream stream, OperationContext clientContext)
{
    clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args)
    {
        if (stream != null)
            stream.Dispose();
    });
}

有谁知道摆脱这种异常是否在我的控制范围之内? 我可以在客户端或服务配置文件上进行任何配置更改吗?

如果您需要我的更多信息,请告诉我。

就我而言,此错误是来自我们组织的HTTP代理服务器 从以下位置找到它: MessageSecurityException.InnerException.Response.Headers

{Mime版本:1.0
X-乌贼错误:ERR_ACCESS_DENIED 0
X缓存:<
X缓存查找: <代理服务器地址>中没有
代理连接:关闭
内容长度:2165
内容类型:text / html
日期:2012年4月25日,星期三10:55:39 GMT
服务器:鱿鱼/3.0.STABLE25
通过:1.0 <代理服务器地址> (squid / 3.0.STABLE25)
}

在我的情况下,也发生了一种文件传输方法,该方法以大小为16384的byte数组传输文件块。将大小减小为10000时,错误已解决。 这意味着代理服务器设置了某种大小限制。

在可直接访问Internet的计算机上,即使阵列大小> 16384,文件传输方法也不会因此错误而失败。

由于只有部分客户端面临此问题,因此它们可能位于防火墙/代理服务器的后面,而该防火墙/代理服务器实际上是阻止访问并返回此错误的服务器?

在我看来,接收MessageSecurityException的客户端未在其请求中提供有效的用户名/密码。

请参阅以下msdn主题http://msdn.microsoft.com/en-us/library/ms733131.aspx

因此,您具有使用匿名身份验证在IIS中配置的Web服务,并且仅少数用户收到403禁止错误。

根据我自己的经验,这通常是由访问ACL控制的系统资源(例如文件系统)时拒绝访问异常引起的。

如果异常连接的每个用户都没有被w3wp.exe进程处理(假定为IIS 7),则该进程通常具有应用程序池标识(IIS APPPOOL / AppPoolName),如果该标识未添加到任何必需的访问控制中,则会列出访问被拒绝的异常将导致IIS响应403错误。

我通常将应用程序池标识添加到组中,然后将该组添加到任何必需的资源中。

如果您无法找出可能导致异常的资源,请尝试在安全事件日志中查找“审计失败”条目以获取线索。 您可能需要配置本地安全策略以记录安全事件。

祝好运

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM