NetworkCredential.Domain Property
Gets or sets the domain or computer name that verifies the credentials.
[Visual Basic] Public Property Domain As String [C#] public string Domain {get; set;} [C++] public: __property String* get_Domain(); public: __property void set_Domain(String*); [JScript] public function get Domain() : String; public function set Domain(String);
Property Value
The name of the domain associated with the credentials.
Remarks
The Domain property specifies the domain or realm to which the user name belongs. Typically, this is the host computer name where the application runs or the user domain for the currently logged in user.
Example
[Visual Basic, C#, C++] The following example uses the Domain property to set the domain associated with the credentials.
[Visual Basic] ' 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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
.NET Framework Security:
- EnvironmentPermission to get the system domain. Associated enumeration: EnvironmentPermissionAccess.Read
See Also
NetworkCredential Class | NetworkCredential Members | System.Net Namespace