S
Stan Rawrysz
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
original request.
I've setup a quick unit test to expose this problem:
[Test]
[Explicit]
[ExpectedException(typeof
(WebException))]
public void CredentialCachePersistenceTest()
{
Stream myStream = null;
Uri myAuthTestUri = new Uri(_authTestUrl);
NetworkCredential myCred = new NetworkCredential(_authTestUser,
_authTestPass, _authTestDomain);
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);
myStream.Close();
myCache.Remove(myAuthTestUri, "Basic");
myResponse.Close();
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?
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
original request.
I've setup a quick unit test to expose this problem:
[Test]
[Explicit]
[ExpectedException(typeof
(WebException))]
public void CredentialCachePersistenceTest()
{
Stream myStream = null;
Uri myAuthTestUri = new Uri(_authTestUrl);
NetworkCredential myCred = new NetworkCredential(_authTestUser,
_authTestPass, _authTestDomain);
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);
myStream.Close();
myCache.Remove(myAuthTestUri, "Basic");
myResponse.Close();
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?