我有一個網站:「https://blahblah.com」驗證網站的憑證
爲了驗證它,我這樣做(工作正常):
NetworkCredential credentials = new NetworkCredential();
credentials.UserName = AppVars.Username;
credentials.Password = AppVars.Password;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = credentials;
//.....
但我怎麼如果我想要添加登錄功能,只需驗證用戶名和密碼?
更新的代碼:
private void btnLogIn_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Username = txtUserName.Text;
Properties.Settings.Default.Password = txtPassword.Text;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, AppVars.ixLibraryConnectionTestURL))
{
try
{
bool isValid = false;
isValid = pc.ValidateCredentials(AppVars.Username, AppVars.Password);
if (isValid == true)
{
//just testing
MessageBox.Show("is valid");
}
else
{
//just testing
MessageBox.Show("is not valid");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
域名看起來是這樣的:https://xxxxxx-services.zzz999.org/pqg_4/lib/api/sdo/rest/v1
你在.NET 3.5中使用C#嗎? – KKP 2012-08-09 14:27:39
正確。即時通訊在.NET 3.5中使用C#。 – Testifier 2012-08-09 14:31:04