Hello everyone,
I am accessing a web site using Windows Integrated authentication. I and the web server are in the same domain using IIS 6.0. Server runs on Windows Server 2003 and the client runs on Windows Vista.
When using the following code segment, there is always 401 error and exception. But when I am using the System.Net.CredentialCache.DefaultCredentials, the code runs successfully. Any ideas what is wrong?
[Code] try { HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://TestWeb/Monitor"); NetworkCredential myCred = new NetworkCredential("domain\\user", "mypass"); CredentialCache myCredentialCache = new CredentialCache(); myCredentialCache.Add(new Uri("http://TestWeb/Monitor"), "NTLM", myCred); req.Credentials = myCredentialCache;
req.ContentType = "text/xml"; req.Method = "GET"; req.Accept = "text/xml";
WebResponse resp = req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); Console.Write(sr.ReadToEnd()); //Just output XML response } catch (Exception ex) { Console.WriteLine(ex.ToString()); }[/Code]
thanks in advance,George