I’m trying to direct the user to a certain page on my site (VB, MVC4) when a given condition is false, but I keep getting a redirect loop:
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
Here’s my code:
Public Class UserValidation
Inherits ActionFilterAttribute
Public Overrides Sub OnActionExecuting(filterContext As System.Web.Mvc.ActionExecutingContext)
If Not DoSomeInternalCheck() Then
filterContext.Result =
New RedirectToRouteResult(
New RouteValueDictionary() From {
{"controller", "Home"},
{"action", "MessagePage"}
}
)
End If
MyBase.OnActionExecuting(filterContext)
End Sub
End Class
What am I missing in order to keep the user off the rest of the site and only have them see this one page?
You need to change this filter so that is doesn’t redirect users if they are accessing the home page you want to redirect them to!
The redirect result sends their browser a message that says “Go to this other URL instead.” When they go to that other URL, their request passes through the same filter, which tells them “Go to this URL [the same one as before] instead.” Eventually the browser gives up and figures (correctly) that you’ve probably hit some kind of infinite redirect loop.