开发者

IIS Authentication. Having both anonymous and windows authentication causes extra headers

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 开发者_StackOverflowworks 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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜