2011-09-14 52 views
1

我有一段时间试图解决使用HttpWebRequest的身份验证问题。IIS身份验证。有匿名和Windows身份验证导致额外的标头

所以我们有一个负载均衡的SOA解决方案。部分解决方案是所有请求都必须经过身份验证(使用Windows身份验证)。解决方案的另一部分是负载均衡器必须匿名访问保持活动页面。因此,我们已经做了appropraite web.config中的部分如下

<location path="hello.aspx" allowOverride="false"> 
    <system.web> 
    <authorization> 
     <allow users="?" /> 
    </authorization> 
    </system.web> 
</location> 
<system.web> 
    <authentication mode="Windows" /> 
    <authorization> 
    <deny users="?" /> 
    </authorization> 
    ... 
</system.web> 

我们已经正确安装一个HttpRequest如下

httpRequest.UseDefaultCredentials = true; 
httpRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Default); 

所以这里的问题。如果只启用集成身份验证,则一切正常。当匿名和集成的身份验证被启用但是(与web.config中所定义),我们得到一个额外的头回来

Cache-Control: private 

这导致我们的客户BARF。我们可以将CachePolicy设置为NoCacheNoStore,但这并不理想,因为其他请求可以并应该被缓存。设置clientCache DisableCache不起作用。

任何想法,将不胜感激。

回答

0

从来没有找到一个解决方案,但不管怎么说,对于那些你有兴趣,这里的解决办法

public Foo ExecuteRequest(RequestCachePolicy cachePolicy, ...) 
{ 
    return ExecuteRequest(new RequestCachePolicy(RequestCacheLevel.Default), ...); 
} 

private Foo ExecuteRequest(RequestCachePolicy cachePolicy, ...) 
{ 
    ... 
    try 
    { 
     ... 
     // Make call using HttpWebRequest 
     ... 
    } 
    catch (WebException ex) 
    { 
     var webResponse = ex.Response as HttpWebResponse; 
     if ((ex.Status == WebExceptionStatus.ProtocolError) && 
      (null != webResponse) && 
      (webResponse.StatusCode == HttpStatusCode.Unauthorized) && 
      (cachePolicy.Level != RequestCacheLevel.NoCacheNoStore)) 
     { 
      return ExecuteRequest(new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore), ...); 
     } 
     ... 
    } 
    ... 
}