2011-09-14 57 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), ...); 
     } 
     ... 
    } 
    ... 
}