[英]Validate domain user credentials with .NET 2
使用Framework 3.5可以解决此问题 ,但是我需要使用.NET Framework 2和C#进行此操作。
我要验证给定的域\\用户和密码组合。 例如:
Username: TheDomain\TheName
Password: ThePassword
还请注意链接中给出的建议解决方案的缺点。
我正在使用的当前解决方案 ,但是请注意错误的负面可能性
您可以使用NetworkCredential.Domain属性
以下代码示例使用Domain属性设置与凭据关联的域
// Create an empty instance of the NetworkCredential class.
NetworkCredential myCredentials = new NetworkCredential("", "", "");
myCredentials.Domain = domain;
myCredentials.UserName = username;
myCredentials.Password = password;
// 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();
这是MSDN链接,供更多阅读
希望对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.