我遇到了一个问题,在嘶吼链接中已经解决了:
当我单击电子邮件验证链接时,激活代码在我的方法输入中为空
但我还有另一个问题。 当我添加另一条这样的路线时:
routes.MapRoute( name: "Password", url: "{controller}/{action}/{passwordResetCode}", defaults: new { controller = "Authentication", action = "ResetPassword" } );
以前的路由不起作用。我的意思是它再次获得空值。每当我想调用它的方法时,我都会手动将其路由带到其他路由的顶部!它得到了工作!你知道,当我想调用它的方法时,我必须更改每个路由的优先级。O.O有什么想法吗?提前谢谢。
Thi 是我项目中的总 rout.config。
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Password",
url: "{controller}/{action}/{passwordResetCode}",
defaults: new { controller = "Authentication", action = "ResetPassword" }
);
routes.MapRoute(
name: "Activation",
url: "{controller}/{action}/{activationCode}",
defaults: new { controller = "Authentication", action = "VerifyAccount" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
这些是操作方法:
[HttpGet]
public ActionResult ResetPassword(string passwordResetCode)
{
ResetPasswordViewModel resetPasswordViewModel = new ResetPasswordViewModel();
ResponseMessage<User> passwordResetRequestedUser = _userService.ResetPasswordCode(passwordResetCode);
if (passwordResetRequestedUser.IsSuccess )
resetPasswordViewModel.ResetCode = passwordResetCode;
return View(resetPasswordViewModel);
}
[HttpGet]
public ActionResult VerifyAccount(string activationCode)
{
if (activationCode != null)
{
ResponseMessage<User> verifiedUser = _userService.VerifyAccount(activationCode);
ModelState.AddModelError("AccountVerification", verifiedUser.ErrorMessages[0]);
return View(verifiedUser.Result.ConvertToUserViewModel());
}
return new HttpNotFoundResult();
}
我建议您准确指定要在自定义路由上使用的控制器和操作,以免覆盖默认路由。
前任。
routes.MapRoute(
name: "Activation",
url: "Authentication/VerifyTheAccount/{activationCode}",
defaults: new { controller = "Authentication", action = "VerifyTheAccount", activationCode = UrlParameter.Optional }
);
routes.MapRoute(
name: "PasswordReset",
url: "Authentication/ResetPassword/{passwordResetCode}",
defaults: new { controller = "Authentication", action = "ResetPassword", passwordResetCode = = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);