【问题标题】:IIS Authentication. Having both anonymous and windows authentication causes extra headersIIS 身份验证。同时拥有匿名和 Windows 身份验证会导致额外的标头
【发布时间】:2011-09-14 20:37:03
【问题描述】:

我正在尝试使用 HttpWebRequest 解决身份验证问题。

所以我们有一个负载平衡的 SOA 解决方案。解决方案的一部分是必须对所有请求进行身份验证(使用 Windows 身份验证)。解决方案的另一部分是负载均衡器必须对保持活动页面具有匿名访问权限。所以我们已经完成了如下适当的 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

这导致我们的客户呕吐。我们可以将 CachePolicy 设置为 NoCacheNoStore 但这并不理想,因为可以并且应该缓存其他请求。设置clientCache DisableCache 无效。

任何想法都将不胜感激。

【问题讨论】:

    标签: iis authentication httpwebrequest anonymous


    【解决方案1】:

    从来没有找到解决方案,但无论如何,对于那些感兴趣的人来说,这里是解决方法

    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), ...);
            }
            ...
        }
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2020-12-21
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 2019-09-20
      • 1970-01-01
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      相关资源
      最近更新 更多