在一个LoginView控件的登录事件中,用了try catch捕捉错误。 但是现在有时会出现thread was being aborted这个错误,怎么查也不知道原因。
登录事件的主要代码如下: protected void login_OnAuthenticate(object sender, AuthenticateEventArgs e)
{
try
{
Login login = (Login)LoginView1.FindControl("Login1");
string userName = login.UserName.Trim();
string password = login.Password.Trim(); /*这里是验证用户的代码,没有任何Response.End(); Response.Redirect();类的代码。*/
}
catch (Exception ex)
{
/*写入错误日志*/ throw ex;
}
}
登录事件的主要代码如下: protected void login_OnAuthenticate(object sender, AuthenticateEventArgs e)
{
try
{
Login login = (Login)LoginView1.FindControl("Login1");
string userName = login.UserName.Trim();
string password = login.Password.Trim(); /*这里是验证用户的代码,没有任何Response.End(); Response.Redirect();类的代码。*/
}
catch (Exception ex)
{
/*写入错误日志*/ throw ex;
}
}
try
{
Login login = (Login)LoginView1.FindControl("Login1");
string userName = login.UserName.Trim();
string password = login.Password.Trim(); /*这里是验证用户的代码,没有任何Response.End(); Response.Redirect();类的代码。*/
}
catch (Exception ex)
{
/*写入错误日志*/ throw ex;
}
能介绍下这段代码您捕捉异常的意图吗?有何意义呢?
有错误也仅仅会出现在Login login = (Login)LoginView1.FindControl("Login1");
设断点调试也没用,因为在本地怎么也不出这错误。 在线上也不是经常出现这个错误。
但是可以确定的是错误肯定是在这个方法里抛出的。
全部代码就这些而已:
protected void login_OnAuthenticate(object sender, AuthenticateEventArgs e)
{
try
{
Login login = (Login)LoginView1.FindControl("Login1");
string userName = login.UserName.Trim();
string password = login.Password.Trim(); if (Membership.ValidateUser(userName, password))
{
StudentSystem studentSystem = new StudentSystem();
Student student = studentSystem.GetStudent(userName);
if (student != null)
{
Session["student"] = student;
e.Authenticated = true;
}
}
}
catch (Exception ex)
{
MethodBase m = MethodBase.GetCurrentMethod();
WriteErrorLog(ex, m, EventEnum.Training_Login); throw ex;
}
}