方法: グループの接続にユーザー情報を割り当てるHow to: Assign User Information to Group Connections

次の例では、グループの接続にユーザー情報を割り当てる方法を示します。このセクションのコードが呼び出される前に、アプリケーションで変数の UserNameSecurelyStoredPassword、および Domain が設定されており、UserName が一意であると想定します。The following example demonstrates how to assign user information to group connections, assuming that the application sets the variables UserName, SecurelyStoredPassword, and Domain before this section of code is called and that UserName is unique.

グループの接続にユーザー情報を割り当てるにはTo assign user information to a group connection

  1. 接続グループ名を作成します。Create a connection group name.

    SHA1Managed Sha1 = new SHA1Managed();  
    Byte[] updHash = Sha1.ComputeHash(Encoding.UTF8.GetBytes(UserName + SecurelyStoredPassword + Domain));  
    String secureGroupName = Encoding.Default.GetString(updHash);  
    
    Dim Sha1 As New SHA1Managed()  
    Dim updHash As [Byte]() = Sha1.ComputeHash(Encoding.UTF8.GetBytes((UserName + SecurelyStoredPassword + Domain)))  
    Dim secureGroupName As [String] = Encoding.Default.GetString(updHash)  
    
  2. 特定の URL の要求を作成します。Create a request for a specific URL. たとえば、次のコードでは URL http://www.contoso.com. の要求が作成されます。For example, the following code creates a request for the URL http://www.contoso.com.

    WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");  
    
    Dim myWebRequest As WebRequest = WebRequest.Create("http://www.contoso.com")  
    
  3. Web 要求の資格情報と ConnectionGroupName を設定し、GetResponse を呼び出して WebResponse オブジェクトを取得します。Set the credentials and Connection GroupName for the Web request, and call GetResponse to retrieve a WebResponse object.

    myWebRequest.Credentials = new NetworkCredential(UserName, SecurelyStoredPassword, Domain);
    myWebRequest.ConnectionGroupName = secureGroupName;  
    
    WebResponse myWebResponse=myWebRequest.GetResponse();  
    
    myWebRequest.Credentials = New NetworkCredential(UserName, SecurelyStoredPassword, Domain)  
    myWebRequest.ConnectionGroupName = secureGroupName  
    
    Dim myWebResponse As WebResponse = myWebRequest.GetResponse()  
    
  4. WebRespose オブジェクトを使用した後、応答ストリームを閉じます。Close the response stream after using the WebRespose object.

    MyWebResponse.Close();  
    
    MyWebResponse.Close()  
    

Example

// Create a connection group name.  
SHA1Managed Sha1 = new SHA1Managed();  
Byte[] updHash = Sha1.ComputeHash(Encoding.UTF8.GetBytes(UserName + SecurelyStoredPassword + Domain));  
String secureGroupName = Encoding.Default.GetString(updHash);  
  
// Create a request for a specific URL.  
WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");  
  
myWebRequest.Credentials = new NetworkCredential(UserName, SecurelyStoredPassword, Domain);
myWebRequest.ConnectionGroupName = secureGroupName;  
  
WebResponse myWebResponse=myWebRequest.GetResponse();  
  
// Insert the code that uses myWebResponse.  
  
MyWebResponse.Close();  
' Create a secure group name.  
Dim Sha1 As New SHA1Managed()  
Dim updHash As [Byte]() = Sha1.ComputeHash(Encoding.UTF8.GetBytes((UserName + SecurelyStoredPassword + Domain)))  
Dim secureGroupName As [String] = Encoding.Default.GetString(updHash)  
  
' Create a request for a specific URL.  
Dim myWebRequest As WebRequest = WebRequest.Create("http://www.contoso.com")  
  
myWebRequest.Credentials = New NetworkCredential(UserName, SecurelyStoredPassword, Domain)  
myWebRequest.ConnectionGroupName = secureGroupName  
  
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()  
  
' Insert the code that uses myWebResponse.  
MyWebResponse.Close()  

参照See also