Is there any way I can implement a convenience method that uses a Controller's protected method(s) without using a base controller, which is recommended against here? For example, I want to return an ActionResult
based on whether a returnUrl
query string param has been passed. What I really want is an extension method like this:
public static class ControllerExtensions {
public static ActionResult RedirectReturnUrlOrDefaultAction(this Controller thisController, string returnUrl, string defaultAction) {
if (!string.IsNullOrEmpty(returnUrl) && thisController.Url.IsLocalUrl(returnUrl)) {
return thisController.Redirect(returnUrl);
}
else {
return thisController.RedirectToAction(defaultAction);
}
}
}
So that I could then say this:
return this.RedirectReturnUrlOrDefaultAction(Request.QueryString["returnUrl"], "Index");
... from within a Controller
. But of course that extension method doesn't compile because for some reason, methods like Redirect
are protected internal
(why are they protected internal
, by the way?)
Is there a decent way I can do this without using a base controller? If not, might this be one good reason to actually use a base controller, or is there something flawed with my design?