Monday, March 30, 2015

PreAuthenticate does not work on CredentialCache.DefaultNetworkCredentials

Hi,


I would like to know why PreAuthenticate=true does not work if i use the CredentialCache.DefaultNetworkCredentials. Is it any reason for this. I'm using .net 2.0 web and consume to the wcf web service. I want to reduce the authentication time that why i plan to use PreAuthenticate=true at my asp.net. But it does not work and keep checking authentication when i call the web services.

wcf web service support ntml and Kerberos. I can't use user and password. I can use default credential only for my requirement.

Is it something wrong on my test or not support?





Regards,



Here is my test code snap.



HttpWebRequest req;
WebResponse resp;
string url = "http://thirpartysystem:7047/SystemService";

NetworkCredential _Cred;
CredentialCache credCache = new CredentialCache();
_Cred = CredentialCache.DefaultNetworkCredentials;

credCache.Add(new Uri(url), "Negotiate",
_Cred);
req = (HttpWebRequest)WebRequest.Create(url);
req.PreAuthenticate = false;
req.Credentials = credCache;
resp = req.GetResponse();
if (req.HaveResponse)
resp.Close();

req = HttpWebRequest.Create(url) as HttpWebRequest;
req.PreAuthenticate = true;
req.Credentials = credCache;
resp = req.GetResponse();
if (req.HaveResponse)
resp.Close();
//Result is
//401
//401
//200
//401
//200

_Cred = new NetworkCredential("user", "password", "domain");
credCache.Add(new Uri(url), "Negotiate",
_Cred);
req = (HttpWebRequest)WebRequest.Create(url);
req.PreAuthenticate = false;
req.Credentials = credCache;
resp = req.GetResponse();
if (req.HaveResponse)
resp.Close();

req = HttpWebRequest.Create(url) as HttpWebRequest;
req.PreAuthenticate = true;
req.Credentials = credCache;
resp = req.GetResponse();
if (req.HaveResponse)
resp.Close();

//Result is
//401
//200
//200





Make Simple & Easy


No comments:

Post a Comment