1

I have created a new action to confirm user account by a token sent in e-mail. It looks like this:

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

And example link to this action would be: localhost:57904/Account/ConfirmToken/ubiJScfyP9zM1WUPCdb54Q2/

The problem is, I never ever get redirected to said Index action from Home controller. I constantly get redirected to Account/Login with previous link as a return URL in parameter. Doesn't matter what I add in the code.

  • when I remove an entire ConfirmToken action, then I get an error
  • when there is an action with nothing in its body, even then I am redirected to Account/Login

I am new to this ASP.NET MVC 4 concept, perhaps I am not doing something properly..? I'm using Visual Studio 2012.

EDIT: I don't know if there's a problem with the code itself. It's an empty project I basically created a few hours ago and made minor modifications to the user registration process. It feels more like the code doesn't refresh since it DID contain redirection to Account/Login in the first place but then I wanted to change it.

EDIT2: Here's my Index/Home action

    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();
    }
7
  • Does Index/Home have an [Authorize] attribute on it? When you check your network requests, does it try to go to Home/Index or does it go direct to Account/Login Commented Oct 21, 2013 at 17:21
  • No, it doesn't have any attributes Commented Oct 21, 2013 at 17:22
  • are you using form authentication? Commented Oct 21, 2013 at 17:22
  • Yes, my Web.config says <authentication mode="Forms">. Commented Oct 21, 2013 at 17:25
  • What does your Index:Home action look like? Commented Oct 21, 2013 at 17:28

1 Answer 1

3

You are facing an authentication issue try logging in before going confirming it will not redirect you the the login view.

If you decorated the class with [Authorize] then you need to allow all user on the controller action, otherwise it will keep redirecting you.

[Authorize]
public class ConfirmController : Controller {

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

}
Sign up to request clarification or add additional context in comments.

2 Comments

Worked like a charm! I had no idea this could be the cause!
I like how the first comment asked about an [Authorize] attribute and he said no.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.