NetworkCredential.UserName プロパティ
資格情報と関連付けられたユーザー名を取得または設定します。
Public Property UserName As String
[C#]
public string UserName {get; set;}
[C++]
public: __property String* get_UserName();public: __property void set_UserName(String*);
[JScript]
public function get UserName() : String;public function set UserName(String);
プロパティ値
資格情報と関連付けられたユーザー名。
使用例
[Visual Basic, C#, C++] 次に示すのは、 UserName プロパティを使用して、資格情報に関連付けるユーザー名を設定するコード例です。
' Create an empty instance of the NetworkCredential class.
Dim myCredentials As New NetworkCredential("", "", "")
myCredentials.Domain = domain
myCredentials.UserName = username
myCredentials.Password = passwd
' Create a WebRequest with the specified URL.
Dim myWebRequest As WebRequest = WebRequest.Create(url)
myWebRequest.Credentials = myCredentials
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "User Credentials:- Domain : {0} , UserName : {1} , Password : {2}", myCredentials.Domain, myCredentials.UserName, myCredentials.Password)
' Send the request and wait for a response.
Console.WriteLine(ControlChars.Cr + ControlChars.Cr + "Request to Url is sent.Waiting for response...Please wait ...")
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' Process the response.
Console.WriteLine(ControlChars.Cr + "Response received sucessfully")
' Release the resources of the response object.
myWebResponse.Close()
[C#]
// Create an empty instance of the NetworkCredential class.
NetworkCredential myCredentials = new NetworkCredential("","","");
myCredentials.Domain = domain;
myCredentials.UserName = username;
myCredentials.Password = passwd;
// Create a WebRequest with the specified URL.
WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Credentials = myCredentials;
Console.WriteLine("\n\nUser Credentials:- Domain : {0} , UserName : {1} , Password : {2}",myCredentials.Domain,myCredentials.UserName,myCredentials.Password);
// Send the request and wait for a response.
Console.WriteLine("\n\nRequest to Url is sent.Waiting for response...Please wait ...");
WebResponse myWebResponse = myWebRequest.GetResponse();
// Process the response.
Console.WriteLine("\nResponse received sucessfully");
// Release the resources of the response object.
myWebResponse.Close();
[C++]
// Create an empty instance of the NetworkCredential class.
NetworkCredential* myCredentials = new NetworkCredential(S"", S"", S"");
myCredentials->Domain = domain;
myCredentials->UserName = username;
myCredentials->Password = passwd;
// Create a WebRequest with the specified URL.
WebRequest* myWebRequest = WebRequest::Create(url);
myWebRequest->Credentials = myCredentials;
Console::WriteLine(S"\n\nUser Credentials:- Domain : {0} , UserName : {1} , Password : {2}",
myCredentials->Domain, myCredentials->UserName, myCredentials->Password);
// Send the request and wait for a response.
Console::WriteLine(S"\n\nRequest to Url is sent.Waiting for response...Please wait ...");
WebResponse* myWebResponse = myWebRequest->GetResponse();
// Process the response.
Console::WriteLine(S"\nResponse received sucessfully");
// Release the resources of the response Object*.
myWebResponse->Close();
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: 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, Common Language Infrastructure (CLI) Standard
.NET Framework セキュリティ:
- EnvironmentPermission (システムからユーザー名を読み取るために必要なアクセス許可) EnvironmentPermissionAccess.Read (関連する列挙体)
参照
NetworkCredential クラス | NetworkCredential メンバ | System.Net 名前空間