Export (0) Print
Expand All

CredentialCache.Remove Method

Deletes a NetworkCredential instance from the cache.

[Visual Basic]
Public Sub Remove( _
   ByVal uriPrefix As Uri, _
   ByVal authType As String _
)
[C#]
public void Remove(
 Uri uriPrefix,
 string authType
);
[C++]
public: void Remove(
 Uri* uriPrefix,
 String* authType
);
[JScript]
public function Remove(
   uriPrefix : Uri,
 authType : String
);

Parameters

uriPrefix
A Uri that specifies the URI prefix of the resources that the credential is used for.
authType
The authentication scheme used by the host named in uriPrefix.

Remarks

The Remove method removes the specified NetworkCredential instance from the CredentialCache. Multiple calls to the Remove method for the same NetworkCredential have no effect.

Example

[Visual Basic, C#, C++] The following example uses the Remove method to delete a NetworkCredential instance from the cache.

[Visual Basic] 
' Create a webrequest with the specified url .
Dim myWebRequest As WebRequest = WebRequest.Create(url)
myWebRequest.Credentials = myCredentialCache
Console.WriteLine(ControlChars.Cr + "Linked CredentialCache to your request.")
' Send the request and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

'Process the response here

Console.Write("Response received successfully.")
'Call 'Remove' method to dispose credentials for current Uri as they would not be; 
   'required in any of the future requests.
myCredentialCache.Remove(myWebRequest.RequestUri, "Basic")
Console.WriteLine(ControlChars.Cr + "Your credentials have now been removed from the program's CredentialCache")
myWebResponse.Close()

[C#] 
// Create a webrequest with the specified url. 
WebRequest myWebRequest = WebRequest.Create(url); 
myWebRequest.Credentials = myCredentialCache;
Console.WriteLine("\nLinked CredentialCache to your request.");
// Send the request and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Process response here.

Console.Write("Response received successfully.");
// Call 'Remove' method to dispose credentials for current Uri as not required further.
myCredentialCache.Remove(myWebRequest.RequestUri,"Basic");
Console.WriteLine("\nYour credentials have now been removed from the program's CredentialCache");
myWebResponse.Close();        

[C++] 
// Create a webrequest with the specified url.
WebRequest* myWebRequest = WebRequest::Create(url);
myWebRequest->Credentials = myCredentialCache;
Console::WriteLine(S"\nLinked CredentialCache to your request.");
// Send the request and wait for response.
WebResponse* myWebResponse = myWebRequest->GetResponse();

// Process response here.

Console::Write(S"Response received successfully.");
// Call 'Remove' method to dispose credentials for current Uri as not required further.
myCredentialCache->Remove(myWebRequest->RequestUri, S"Basic");
Console::WriteLine(S"\nYour credentials have now been removed from the program's CredentialCache");
myWebResponse->Close();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

CredentialCache Class | CredentialCache Members | System.Net Namespace

Show:
© 2014 Microsoft