I have a filter attribute that checks for a route parameter and if it doesn't exits I apply some logic to check if the current request needs to be redirected to another route.
My code looks like this
Public Overrides Sub OnActionExecuting(filterContext As ActionExecutingContext)
If Not filterContext.RouteData.Values.ContainsKey("SearchKey") Then
strSearchKey = strFrom.ToString.Substring(strFrom.ToString.IndexOf("/") + 1)
strFrom = strFrom.ToString.Substring(0, strFrom.ToString.IndexOf("/") + 1)
If Not IsNullOrEmpty(strSearchKey) Then
Dim values As New Web.Routing.RouteValueDictionary
values.Add("SearchKey", strSearchKey)
values.Add("From", strFrom)
values.Add("controller", "SearchResults")
values.Add("action", "Category")
filterContext.Result = New RedirectToRouteResult("SearchCategory", values)
'filterContext.Result.ExecuteResult(filterContext)
End If
End If
End Sub
This is what I'm doing to get it to redirect but the problem is that it causes an infinite loop and I can't find the reason why it just keeps hitting this same route which is the one I'm redirecting from over and over.