IIS 身份验证。同时使用匿名和 Windows 身份验证会导致额外的标头

发布于 2024-12-04 09:17:43 字数 1023 浏览 2 评论 0原文

我正在尝试解决使用 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 但这并不理想,因为其他请求可以而且应该被缓存。设置 clientCacheDisableCache 没有效果。

任何想法将不胜感激。

i'm having a heck of a time trying to resolve an issue with authentication using HttpWebRequest.

So we have a SOA solutation that is being load balanced. Part of the solution is that all requests must be authenticated (using Windows Authentication). The other part of the solution is that the load balancer must have anonymous access to a keep alive page. So we've done the appropraite web.config sections as below

<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>

we've correctly setup an httpRequest as below

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

so here's the problem. When only integrated authentication is enabled everything works great. However when both anonymous and integrated authentication are enabled (with the web.config defined above) we get an extra header coming back

Cache-Control: private

This is causing our client to barf. We can set the CachePolicy to NoCacheNoStore but that's not ideal because other requests can and should be cached. Setting the clientCache DisableCache has no effect.

Any ideas would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终陌 2024-12-11 09:17:43

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

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

Never did find a solution but anyways, for those of you that are interested here's the workaround

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), ...);
        }
        ...
    }
    ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文