共用方式為


HttpWebRequest.ConnectionGroupName 屬性

定義

取得或設定要求的連接組名。

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

屬性值

此要求的連接組名。 預設值為 null

範例

下列程式代碼範例示範如何使用使用者資訊來形成連接群組,假設呼叫此程式代碼之前,應用程式會先設定變數 usernamepassworddomain

// 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()

備註

謹慎

WebRequestHttpWebRequestServicePointWebClient 已經過時,您不應該將它們用於新的開發。 請改用 HttpClient

ConnectionGroupName 屬性可讓您將要求與連接群組產生關聯。 當您的應用程式向不同使用者提出要求時,這非常有用,例如從資料庫伺服器擷取客戶資訊的網站。

給繼承者的注意事項

每個連接群組都會為伺服器建立其他連線。 這可能會導致超過該伺服器的 ConnectionLimit 屬性所設定的連線數目。

適用於

另請參閱