Credentials persist after CredentialCache.Remove()

Discussion in 'ASP .Net Security' started by Stan Rawrysz, Apr 14, 2005.

  1. Stan Rawrysz

    Stan Rawrysz Guest

    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?
    Stan Rawrysz, Apr 14, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig
    Replies:
    1
    Views:
    10,945
    shobhaiyer
    Oct 3, 2007
  2. Guest
    Replies:
    1
    Views:
    465
    yuri vanzine
    Dec 9, 2003
  3. Liviu Olaru
    Replies:
    3
    Views:
    195
    Jan Tielens
    Jan 21, 2004
  4. Eric
    Replies:
    1
    Views:
    144
    Dominick Baier [DevelopMentor]
    Apr 21, 2006
  5. Liviu Olaru
    Replies:
    3
    Views:
    187
    Jan Tielens
    Jan 21, 2004
Loading...

Share This Page