C# ASP.NET MVC 4错误重定向

C# ASP.NET MVC 4错误重定向,c#,asp.net,asp.net-mvc-4,redirect,C#,Asp.net,Asp.net Mvc 4,Redirect,我创建了一个新操作,通过电子邮件中发送的令牌确认用户帐户。看起来是这样的: public ActionResult ConfirmToken(string id) { bool isConfirmed; isConfirmed = WebSecurity.ConfirmAccount(id); if (isConfirmed) { return RedirectToAction("Inde

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

    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/

问题是,我从未从主控制器重定向到上述索引操作。我经常被重定向到帐户/登录,并在参数中使用上一个链接作为返回URL。不管我在代码中添加了什么

  • 当我删除整个ConfirmToken操作时,就会出现一个错误
  • 当一个动作的主体中没有任何内容时,即使这样,我也会被重定向到Account/Login
我对ASP.NETMVC4这个概念还不熟悉,也许我做得不太好。。?我正在使用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)
  {
   //..
  }

}

Index/Home是否有[Authorize]属性?当你检查你的网络请求时,它是尝试转到主页/索引还是直接转到帐户/登录?否,它没有任何属性。你在使用表单身份验证吗?是的,我的Web.config说。你的索引:主页操作看起来像什么?工作起来很有魅力!我不知道这可能是原因!我喜欢第一条评论询问[授权]属性的方式,他拒绝了。