指定したユーザー名とパスワードを使用して、NetworkCredential クラスの新しいインスタンスを初期化します。
名前空間: System.Net
アセンブリ: System (system.dll 内)
構文
'宣言
Public Sub New ( _
userName As String, _
password As String _
)
'使用
Dim userName As String
Dim password As String
Dim instance As New NetworkCredential(userName, password)
public NetworkCredential (
string userName,
string password
)
public:
NetworkCredential (
String^ userName,
String^ password
)
public NetworkCredential (
String userName,
String password
)
public function NetworkCredential (
userName : String,
password : String
)
パラメータ
- userName
資格情報と関連付けられたユーザー名。
- password
資格情報と関連付けられたユーザー名のパスワード。
解説
コンストラクタは、UserName プロパティを userName に設定し、Password プロパティを password に設定して、NetworkCredential オブジェクトを初期化します。
使用例
指定したユーザー名とパスワードを使用して、NetworkCredential オブジェクトを作成するコード例を次に示します。
' Call the constructor to create an instance of NetworkCredential with the
' specified user name and password.
Dim myCredentials As New NetworkCredential(username, passwd)
' Create a WebRequest with the specified URL.
Dim myWebRequest As WebRequest = WebRequest.Create(url)
myCredentials.Domain = ___domain
myWebRequest.Credentials = myCredentials
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "Credentials Domain : {0} , UserName : {1} , Password : {2}", myCredentials.Domain, myCredentials.UserName, myCredentials.Password)
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "Request to Url is sent.Waiting for response...")
' Send the request and wait for a response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' Process the response.
Console.WriteLine(ControlChars.Cr + "Response received successfully.")
' Release the resources of the response object.
myWebResponse.Close()
// Call the onstructor to create an instance of NetworkCredential with the
// specified user name and password.
NetworkCredential myCredentials = new NetworkCredential(username,passwd);
// Create a WebRequest with the specified URL.
WebRequest myWebRequest = WebRequest.Create(url);
myCredentials.Domain = ___domain;
myWebRequest.Credentials = myCredentials;
Console.WriteLine("\n\nCredentials Domain : {0} , UserName : {1} , Password : {2}",
myCredentials.Domain, myCredentials.UserName, myCredentials.Password);
Console.WriteLine("\n\nRequest to Url is sent.Waiting for response...");
// Send the request and wait for a response.
WebResponse myWebResponse = myWebRequest.GetResponse();
// Process the response.
Console.WriteLine("\nResponse received successfully.");
// Release the resources of the response object.
myWebResponse.Close();
// Call the onstructor to create an instance of NetworkCredential with the
// specified user name and password.
NetworkCredential^ myCredentials = gcnew NetworkCredential( username,passwd );
// Create a WebRequest with the specified URL.
WebRequest^ myWebRequest = WebRequest::Create( url );
myCredentials->Domain = ___domain;
myWebRequest->Credentials = myCredentials;
Console::WriteLine( "\n\nCredentials Domain : {0} , UserName : {1} , Password : {2}",
myCredentials->Domain, myCredentials->UserName, myCredentials->Password );
Console::WriteLine( "\n\nRequest to Url is sent.Waiting for response..." );
// Send the request and wait for a response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();
// Process the response.
Console::WriteLine( "\nResponse received successfully." );
// Release the resources of the response object.
myWebResponse->Close();
// Call the onstructor to create an instance of
// NetworkCredential with the
// specified user name and password.
NetworkCredential myCredentials = new NetworkCredential(userName,
passwd);
// Create a WebRequest with the specified URL.
WebRequest myWebRequest = WebRequest.Create(url);
myCredentials.set_Domain(___domain);
myWebRequest.set_Credentials(myCredentials);
Console.WriteLine("\n\nCredentials Domain : {0} , UserName : "
+ "{1} , Password : {2}", myCredentials.get_Domain(),
myCredentials.get_UserName(), myCredentials.get_Password());
Console.WriteLine("\n\nRequest to Url is sent.Waiting for "
+ "response...");
// Send the request and wait for a response.
WebResponse myWebResponse = myWebRequest.GetResponse();
// Process the response.
Console.WriteLine("\nResponse received successfully.");
// Release the resources of the response object.
myWebResponse.Close();
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0