greg84
greg84

Reputation: 7609

Orchard CMS continues executing request after permanent redirect from IActionFilter

We have a website that uses Orchard CMS and we've written a "RedirectFilter" to do permanent redirects on legacy URLs (aliases that don't match the AutoroutePart pattern for the relevant Content Item).

The filter implements IActionFilter and inherits FilterProvider. It works fine and when it does a redirect it calls the following method in OnActionExecuting:

filterContext.HttpContext.Response.RedirectPermanent(targetPath, true);

According to the documentation the second parameter suggests that a ThreadAbortException will be thrown to abort the current request. However, the request is still processed for the legacy URL, I know this because the Part Drivers still execute for both the legacy and new URLs.

How can I abort the request from the filter without Orchard continuing to execute it?

Upvotes: 1

Views: 370

Answers (1)

greg84
greg84

Reputation: 7609

Just worked this out. Need to use this instead:

filterContext.Result = new RedirectResult(targetPath, true);

I'm guessing you can't call RedirectPermenant inside a filter.

Upvotes: 1

Related Questions