您好我正在尝试通过此方法验证用户
protected void btnLogin_Click(object sender, EventArgs e)
{
string email = txtEmail.Text;
string password = txtPassword.Text;
try
{
bool loginResult = SingletonManager.Instance.FrontendFactories.UserFrontendFactory.LoginUser(email, FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5"), chkRememberMe.Checked);
if (loginResult == true)
{
FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, true);
Context.Items.Add("email", txtEmail.Text);
}
else
{
txtEmail.CssClass += " " + "txt-error-message";
errorIconmaEmail.Visible = true;
txtPassword.CssClass += " " + "txt-error-message";
errorIconPassword.Visible = true;
}
}
catch (Exception ex)
{
lblerror.Text = ex.Message;
}
}
现在我知道它是一个void方法,而void方法不会返回值,但是有一个解决方法是在else块中创建一个bool(而不是当前代码),例如bool isValidUser = false,所以javascript函数将根据此bool的值处理错误消息样式。仅供参考我正在访问公共变量背后的代码。
<%= isValidUser %>