ICredentials Interface
.NET Framework (current version)
Provides the base authentication interface for retrieving credentials for Web client authentication.
Assembly: System (in System.dll)
| Name | Description | |
|---|---|---|
![]() | GetCredential(Uri, String) | Returns a NetworkCredential object that is associated with the specified URI, and authentication type. |
The ICredentials interface provides the GetCredential method to objects that supply network credentials to applications.
The following example illustrates how to use the ICredentials interface.
Class CredentialInfo Public uriObj As Uri Public authenticationType As [String] Public networkCredentialObj As NetworkCredential Public Sub New(uriObj As Uri, authenticationType As [String], networkCredentialObj As NetworkCredential) Me.uriObj = uriObj Me.authenticationType = authenticationType Me.networkCredentialObj = networkCredentialObj End Sub 'NewNew End Class 'CredentialInfo Private arrayListObj As ArrayList Public Sub New() arrayListObj = New ArrayList() End Sub 'NewNew Public Sub Add(uriObj As Uri, authenticationType As [String], credential As NetworkCredential) ' adds a 'CredentialInfo' object into a list arrayListObj.Add(New CredentialInfo(uriObj, authenticationType, credential)) End Sub 'Add ' Remove the 'CredentialInfo' object from the list which matches to the given 'Uri' and 'AuthenticationType' Public Sub Remove(uriObj As Uri, authenticationType As [String]) Dim index As Integer For index = 0 To arrayListObj.Count - 1 Dim credentialInfo As CredentialInfo = CType(arrayListObj(index), CredentialInfo) If uriObj.Equals(credentialInfo.uriObj) And authenticationType.Equals(credentialInfo.authenticationType) Then arrayListObj.RemoveAt(index) End If Next index End Sub 'Remove Public Function GetCredential(uriObj As Uri, authenticationType As [String]) As NetworkCredential Implements ICredentials.GetCredential Dim index As Integer For index = 0 To arrayListObj.Count - 1 Dim credentialInfoObj As CredentialInfo = CType(arrayListObj(index), CredentialInfo) If uriObj.Equals(credentialInfoObj.uriObj) And authenticationType.Equals(credentialInfoObj.authenticationType) Then Return credentialInfoObj.networkCredentialObj End If Next index Return Nothing End Function 'GetCredential
Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 3.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Show:
