Share via


HttpWebRequest.ConnectionGroupName Properti

Definisi

Mendapatkan atau mengatur nama grup koneksi untuk permintaan tersebut.

public:
 virtual property System::String ^ ConnectionGroupName { System::String ^ get(); void set(System::String ^ value); };
public override string? ConnectionGroupName { get; set; }
public override string ConnectionGroupName { get; set; }
member this.ConnectionGroupName : string with get, set
Public Overrides Property ConnectionGroupName As String

Nilai Properti

Nama grup koneksi untuk permintaan ini. Nilai defaultnya adalah null.

Contoh

Contoh kode berikut menunjukkan cara menggunakan informasi pengguna untuk membentuk grup koneksi, dengan asumsi bahwa variabel username, , passworddan domain diatur oleh aplikasi sebelum kode ini dipanggil.

// Create a secure group name.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
SHA1Managed^ Sha1 = gcnew SHA1Managed;
array<Byte>^updHash = Sha1->ComputeHash( Encoding::UTF8->GetBytes( "usernamepassworddomain" ) );
String^ secureGroupName = Encoding::Default->GetString( updHash );

// Create a request for a specific URL.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );

// Set the authentication credentials for the request.      
myWebRequest->Credentials = gcnew NetworkCredential( "username","password","domain" );
myWebRequest->ConnectionGroupName = secureGroupName;

// Get the response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Insert the code that uses myWebResponse here.
// Close the response.
myWebResponse->Close();
// Create a secure group name.
// This example uses the SHA1 algorithm.
// Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
SHA1Managed Sha1 = new SHA1Managed();
Byte[] updHash = Sha1.ComputeHash(Encoding.UTF8.GetBytes("username" + "password" +  "domain"));
String secureGroupName = Encoding.Default.GetString(updHash);

// Create a request for a specific URL.
WebRequest myWebRequest=WebRequest.Create("http://www.contoso.com");

// Set the authentication credentials for the request.
myWebRequest.Credentials = new NetworkCredential("username", "password", "domain");
myWebRequest.ConnectionGroupName = secureGroupName;

// Get the response.
WebResponse myWebResponse=myWebRequest.GetResponse();

// Insert the code that uses myWebResponse here.

// Close the response.
myWebResponse.Close();
' Create a secure group name.
' This example uses the SHA1 algorithm.
' Due to collision problems with SHA1, Microsoft recommends SHA256 or better.
Dim Sha1 As New SHA1Managed()
Dim updHash As [Byte]() = Sha1.ComputeHash(Encoding.UTF8.GetBytes(("username" + "password" + "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")
   
' Set the authentication credentials for the request.      
myWebRequest.Credentials = New NetworkCredential("username", "password", "domain")
myWebRequest.ConnectionGroupName = secureGroupName
   
' Get the response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
   
' Insert the code that uses myWebResponse here.
' Close the response.
myWebResponse.Close()

Keterangan

Properti ConnectionGroupName memungkinkan Anda mengaitkan permintaan dengan grup koneksi. Ini berguna ketika aplikasi Anda membuat permintaan ke satu server untuk pengguna yang berbeda, seperti situs Web yang mengambil informasi pelanggan dari server database.

Catatan Bagi Inheritor

Setiap grup koneksi membuat koneksi tambahan untuk server. Ini dapat mengakibatkan melebihi jumlah koneksi yang ditetapkan oleh properti untuk server tersebut ConnectionLimit .

Berlaku untuk

Lihat juga