로그인 프로세스를 처리하는 LINQ 문이 있습니다. 유효한 사용자 이름과 암호 조합이 전달되면 제대로 작동합니다. 그러나 유효하지 않은 자격 증명을 테스트 할 때 < < <으로 표시된 줄에 NullReferenceException
오류가 표시됩니다. -------------- 잘못된 자격 증명을 올바르게 처리하는 데 도움이 필요하십니까? 더 DBLogIn
기록 당신이주는 기준과 일치하지가 있다면Linq Select 문 도움말 필요 - FirstOrDefault 사용 후 NullReferenceException
public int _accountID;
public int _securityLevelID;
public void GetLoginInfo(string EmailAddress, string Password)
{
LoginItem l = null;
{
try
{
using (RootsDataContext RDC = new RootsDataContext())
l = (from a in RDC.DBLogIns
where a.EmailAddress == EmailAddress
&& a.Password == Password
&& a.IsActive == 1
select new LoginItem
{
AccountIDFK = a.AccountIDFK,
SecurityLevelIDFK = a.SecurtityLevelIDFK,
}).FirstOrDefault();
_accountID = (int)l.AccountIDFK; <<<----------------
_securityLevelID = (int)l.SecurityLevelIDFK;
if (_accountID < 1 || _accountID == null)
{
lbl_LoginStatus.Text = "Invalid";
}
}
catch (Exception ex)
{
string error = ex.Message;
}
if (_accountID > 0)
{
if (_accountID == 1 && _securityLevelID == 1) // [Quentin]
{
Response.Redirect("~/AccountsMaster.aspx");
}
if (_accountID > 1 && _securityLevelID == 2) // [Companies]
{
Response.Redirect("~/CompanyMaster.aspx");
}
if (_accountID > 1 && _securityLevelID == 3) // [Branch]
{
Response.Redirect("~/BranchMaster.Aspx");
}
if (_accountID > 1 && _securityLevelID == 4) // [Clients]
{
Response.Redirect("~/Home.aspx");
}
}
}
}