Credentials persist after CredentialCache.Remove()
So I've been banging my head against the wall here for a while now and
cannot find any useful information regarding this issue that I'm having.
The problem is that after I create a WebRequest object with a
CredentialCache and make a call to the resource, all subsequent requests
to that resource, even if I don't set the cache to the next WebRequest
and set the cache to null, end up using that NetworkCredential from the
I've setup a quick unit test to expose this problem:
public void CredentialCachePersistenceTest()
Stream myStream = null;
Uri myAuthTestUri = new Uri(_authTestUrl);
NetworkCredential myCred = new NetworkCredential(_authTestUser,
CredentialCache myCache = new CredentialCache();
myCache.Add(myAuthTestUri, "Basic", myCred);
WebRequest myReq = WebRequest.Create(myAuthTestUri);
myReq.Credentials = myCache;
WebResponse myResponse = myReq.GetResponse();
myStream = myResponse.GetResponseStream();
Console.WriteLine("Stream1.CanRead = " + myStream.CanRead);
myCache = null;
WebRequest myReq2 = WebRequest.Create(new Uri(_authTestUrl));
WebResponse myResponse2 = myReq2.GetResponse();
myStream = myResponse2.GetResponseStream();
Console.WriteLine("Stream2.CanRead = " + myStream.CanRead);
The web site I'm connecting to is set to have anonymous access off with
"Basic Authentication" and "Integrated Windows Security" on.
Has anyone come accross this problem? Is there a solution?
|All times are GMT. The time now is 06:03 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.