簡體   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