繁体   English   中英

ASP.NET MVC 4错误的重定向

[英]ASP.NET MVC 4 Wrong redirection

我创建了一个新操作,通过电子邮件中发送的令牌确认用户帐户。 它看起来像这样:

    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 / ubiJSffyP9zM1WUPCdb54Q2 /

问题是,我永远不会被重定向到Home控制器的Index动作。 我不断被重定向到帐户/登录,前一个链接作为参数中的返回URL。 无论我在代码中添加什么。

  • 当我删除整个ConfirmToken动作时,我收到一个错误
  • 当行动中没有任何内容时,即使这样,我也会被重定向到帐户/登录

我是这个ASP.NET MVC 4概念的新手,也许我没有做正确的事情......? 我正在使用Visual Studio 2012。

编辑:我不知道代码本身是否存在问题。 这是我几个小时前基本上创建的一个空项目,并对用户注册过程进行了少量修改。 感觉更像代码没有刷新,因为它首先包含重定向到帐户/登录,但后来我想改变它。

编辑2:这是我的索引/主页操作

    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();
    }

您正面临身份验证问题尝试登录,然后确认它不会重定向您的登录视图。

如果您使用[Authorize]修饰了类,则需要允许所有用户执行控制器操作,否则它将继续重定向您。

[Authorize]
public class ConfirmController : Controller {

  [AllowAnonymous]  
  public ActionResult ConfirmToken(string id)
  {
   //..
  }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM