次の方法で共有


ICredentials インターフェイス

Web クライアント認証の資格情報を取得するために基本認証インターフェイスを提供します。

この型のすべてのメンバの一覧については、ICredentials メンバ を参照してください。

Public Interface ICredentials
[C#]
public interface ICredentials
[C++]
public __gc __interface ICredentials
[JScript]
public interface ICredentials

ICredentials を実装するクラス

クラス 説明
CredentialCache 複数の資格情報にストレージを提供します。
NetworkCredential 基本認証、ダイジェスト認証、NTLM 認証、Kerberos 認証などのパスワードに基づく認証方式に資格情報を提供します。

解説

ICredentials インターフェイスには、アプリケーションにネットワーク資格情報を提供するオブジェクト用の GetCredential メソッドが用意されています。

使用例

[Visual Basic, C#, C++] ICredentials インターフェイスを使用する方法を次の例に示します。

 

 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 'New
 End Class 'CredentialInfo
 
 Private arrayListObj As ArrayList
 
 
 Public Sub New()
     arrayListObj = New ArrayList()
 End Sub 'New
 
 
 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

[C#] 
class CredentialList : ICredentials
{
    class CredentialInfo
    {
        public Uri uriObj;
        public String authenticationType;
        public NetworkCredential networkCredentialObj;
  
        public CredentialInfo(Uri uriObj, String authenticationType, NetworkCredential networkCredentialObj)
        {
            this.uriObj = uriObj;
            this.authenticationType = authenticationType;
            this.networkCredentialObj = networkCredentialObj;
        }
    }

    private ArrayList arrayListObj;

    public CredentialList()
    {
        arrayListObj = new ArrayList();
    }

    public void Add (Uri uriObj, String authenticationType, NetworkCredential credential)
    {
        // Add a 'CredentialInfo' object into a list.
        arrayListObj.Add (new CredentialInfo(uriObj, authenticationType, credential));      
    }
    // Remove the 'CredentialInfo' object from the list that matches to the given 'Uri' and 'AuthenticationType'
    public void Remove (Uri uriObj, String authenticationType)
    {
        for(int index=0;index < arrayListObj.Count; index++)
        {
            CredentialInfo credentialInfo = (CredentialInfo)arrayListObj[index];
            if(uriObj.Equals(credentialInfo.uriObj)&& authenticationType.Equals(credentialInfo.authenticationType))
                arrayListObj.RemoveAt(index);
        }
    }
    public NetworkCredential GetCredential (Uri uriObj, String authenticationType)
    {
        for(int index=0;index < arrayListObj.Count; index++)
        {
            CredentialInfo credentialInfoObj = (CredentialInfo)arrayListObj[index];
            if(uriObj.Equals(credentialInfoObj.uriObj) && authenticationType.Equals(credentialInfoObj.authenticationType))
                return credentialInfoObj.networkCredentialObj;
        }
        return null;
    }
};

[C++] 
__gc class CredentialList : public ICredentials {
   __gc class CredentialInfo {
   public:
      Uri* uriObj;
      String* authenticationType;
      NetworkCredential* networkCredentialObj;

      CredentialInfo(Uri* uriObj, String* authenticationType, NetworkCredential* networkCredentialObj) {
         this->uriObj = uriObj;
         this->authenticationType = authenticationType;
         this->networkCredentialObj = networkCredentialObj;
      }
   };

private:
   ArrayList*  arrayListObj;

public:
   CredentialList() {
      arrayListObj = new ArrayList();
   }

   void Add (Uri* uriObj, String* authenticationType, NetworkCredential* credential) {
      // Add a 'CredentialInfo' object into a list.
      arrayListObj->Add (new CredentialInfo(uriObj, authenticationType, credential));
   }

   // Remove the 'CredentialInfo' object from the list that matches to the given 'Uri' and 'AuthenticationType'
   void Remove (Uri* uriObj, String* authenticationType) {
      for (int index=0;index < arrayListObj->Count; index++) {
         CredentialInfo* credentialInfo = dynamic_cast<CredentialInfo*>(arrayListObj->Item[index]);
         if (uriObj->Equals(credentialInfo->uriObj)&& authenticationType->Equals(credentialInfo->authenticationType))
            arrayListObj->RemoveAt(index);
      }
   }

   NetworkCredential * GetCredential (Uri* uriObj, String* authenticationType) {
      for (int index=0;index < arrayListObj->Count; index++) {
         CredentialInfo* credentialInfoObj = dynamic_cast<CredentialInfo*>(arrayListObj->Item[index]);
         if (uriObj->Equals(credentialInfoObj->uriObj) && authenticationType->Equals(credentialInfoObj->authenticationType))
            return credentialInfoObj->networkCredentialObj;
      }
      return 0;
   }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Net

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System (System.dll 内)

参照

ICredentials メンバ | System.Net 名前空間