我想知道如果有使用我输入的密码的网络登录,我如何创建代码来检查数据库。我在“Global.asax”中这样做
谢谢你们!
编辑:我试图编写的代码
SqlCommand comando = new SqlCommand("Select * from Usuario where = @UserID", conexao);
comando.Connection = conexao;
SqlParameter param = new SqlParameter();
param.ParameterName = "@UserID";
param.Value = login;
comando.Parameters.Add(param);
我做了类似的事情,但是使用了 Active Directory。一探究竟:
任务是检查 Active Directory 是否存在网络登录
try
{
using (var entry = new DirectoryEntry("LDAP://" + dominio, dominio + "\\" + login, senha))
{
using (var directorySearcher = new DirectorySearcher(entry))
{
matricula = TratarLDAPInjection(matricula);
directorySearcher.Filter = "(sAMAccountName=" + matricula + ")";
SearchResult result = directorySearcher.FindOne();
if (result == null)
{
throw new AguException(string.Format("Não é possível localizar o usuário de matrícula {0} no banco de dados da MyEnterprise.", matricula));
}
}
}
}
catch
{
Response.Redirect("~/Erro.aspx");
}