Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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?

<br />           try<br />            {<br />                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://TestWeb/Monitor");<br />                <br />                NetworkCredential myCred = new NetworkCredential("domain\\user", "mypass");<br />                CredentialCache myCredentialCache = new CredentialCache();<br />                myCredentialCache.Add(new Uri("http://TestWeb/Monitor"), "NTLM", myCred);<br />                req.Credentials = myCredentialCache;<br /><br />                req.ContentType = "text/xml";<br />                req.Method = "GET";<br />                req.Accept = "text/xml";<br /><br />                WebResponse resp = req.GetResponse();<br />                StreamReader sr = new StreamReader(resp.GetResponseStream());<br />                Console.Write(sr.ReadToEnd()); //Just output XML response<br />            }<br />            catch (Exception ex)<br />            {<br />                Console.WriteLine(ex.ToString());<br />            }<br />



thanks in advance,
George
Posted

1 solution

George_George wrote:
NetworkCredential myCred = new NetworkCredential("domain\\user", "mypass");


Try the constructor taking 3 arguments. Seems it might mess up on the domain part.

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900