有人可以帮我弄这个吗。我希望将此代码放入尝试捕获中。但我不能说如何最好地实现这一点:
public JsonResult JsonLogin(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
return Json(new JsonDialog
{
Redirect = returnUrl,
Success = true
});
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed
return Json(new JsonDialog
{
Errors = GetErrorsFromModelState(),
Success = false
});
}
我应该把包括第一个“if”在内的所有代码都放在try catch中吗?