Scott Selby
Scott Selby

Reputation: 9570

Call to Redirect executed but nothing happens

I have a Login Controller that, if the user is already logged in but still tries to get to Login Controller, redirects to the MyEvents controller.

In my code the line RedirectToAction is being executed, but nothing happens. I know you can not redirect in a Ajax call, but this is an actual GET request from another page to /Login. There doesn't seem to be any reason why it wouldn't redirect for me.

Function Index(Optional ReturnUrl As String = "") As ActionResult
  If HttpContext.User.Identity.IsAuthenticated Then
     RedirectToAction("Index", "MyEvents") 'This Line is being read, but nothing happens
  End If

  Return View()
End Function

Upvotes: 1

Views: 283

Answers (1)

jrummell
jrummell

Reputation: 43077

The RedirectToAction method doesn't actually perform the redirect, it returns a result that gets sent to the client telling it redirect. Add a Return and it will work.

Return RedirectToAction("Index", "MyEvents")

Upvotes: 3

Related Questions