我创建了一个新操作来通过电子邮件中发送的令牌确认用户帐户。它看起来像这样:
public ActionResult ConfirmToken(string id)
{
bool isConfirmed;
isConfirmed = WebSecurity.ConfirmAccount(id);
if (isConfirmed)
{
return RedirectToAction("Index", "Home", new { Message = ManageMessageId.ConfirmSuccess });
}
else
{
return RedirectToAction("Index", "Home", new { Message = ManageMessageId.ConfirmFail });
}
}
此操作的示例链接为:localhost:57904/Account/ConfirmToken/ubiJScfyP9zM1WUPCdb54Q2/
问题是,我从来没有从 Home 控制器重定向到所述 Index 操作。我经常被重定向到帐户/登录,之前的链接作为参数中的返回 URL。我在代码中添加什么都没关系。
- 当我删除整个 ConfirmToken 操作时,我收到一个错误
- 当有一个动作没有任何内容时,即使这样我也会被重定向到帐户/登录
我是这个 ASP.NET MVC 4 概念的新手,也许我没有正确地做某事..?我正在使用 Visual Studio 2012。
编辑:我不知道代码本身是否有问题。这是一个空的项目,我基本上是几个小时前创建的,并对用户注册过程进行了少量修改。感觉更像是代码没有刷新,因为它首先包含重定向到帐户/登录,但后来我想更改它。
EDIT2:这是我的索引/主页操作
public ActionResult Index(ManageMessageId? message)
{
ViewBag.StatusMessage =
message == ManageMessageId.RegisterSuccess ? "An e-mail has been sent to the e-mail address you provided. It contains instructions how to confirm your account and finish the registration process. If you cannot see the e-mail in your inbox, please check spam folder."
: message == ManageMessageId.ConfirmSuccess ? "Your account has been successfully confirmed and you can now login."
: message == ManageMessageId.ConfirmFail ? "An error occured while activating your account. Please mail our support for assistance."
: "";
return View();
}