Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

PreAuthenticate does not work on CredentialCache.DefaultNetworkCredentials

$
0
0

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? Is it any way to reduce checking authentication on each web services calling?

Here is my code sample

        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

Regards,


Viewing all articles
Browse latest Browse all 4737

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>