anonymous and basic authentication problem

From: Tony Wright (tonyz.wrightz_at_consultant.com)
Date: 02/23/04


Date: 22 Feb 2004 19:14:09 -0800

Hi,

I am having a problem with authentication of a web service. The web
service is a searching service, which returns different results
depending on whether the user is public or trade. Trade users log in,
whereas public users are anonymous.

To access the service, I use the following code
public static FasWebService.FasWS GetFasWebService()
{
        string UserName = HttpContext.Current.Request.ServerVariables["AUTH_USER"];
        string Password = HttpContext.Current.Request.ServerVariables["AUTH_PASSWORD"];

        if (UserName.Length==0)
        {
                return new FasWebService.FasWS();
        }
        else
        {
                System.Net.NetworkCredential FasCred = new
System.Net.NetworkCredential(UserName,Password);
                System.Net.CredentialCache cache = new System.Net.CredentialCache();
                FasWebService.FasWS ws = new FasWebService.FasWS();
                cache.Add(new Uri(ws.Url),"basic",FasCred);
                ws.PreAuthenticate=true;
                ws.Credentials=cache;
                ws.ConnectionGroupName=UserName;
                return ws;
        }
}

Tracing through the code, I find that the credentials are being set on
the web service, however inside the web service all it is returning is

HttpContext.Current.Request.IsAuthenticated==false

I assume it is falling back to anonymous authentication, even though I
am specifying the credentials. The security for the webservice is
Anonymous Authentication AND Basic authentication.

Anyone have suggestions on what is going wrong?

Thanks,
Tony