you can define Routes in RouteConfig like this:
routes.MapRoute(
name: "Error",
url: "error/generalerror",
defaults: new { controller = "Error", action = "GeneralError" },
namespaces: new[] { "YourApplication.namespace" }
);
routes.MapRoute(
name: "CustomError",
url: "error/customerror",
defaults: new { controller = "Error", action = "CustomError" },
namespaces: new[] { "YourApplication.namespace" }
);
Then in your ActionFilter
class you can have a default two constructors
public YourFilterAttribute()
: this("Error")
{}
public YourFilterAttribute(string route)
{
//store route in some class variable
}
That way most classes would use the attibute like this: [YourFilter]
and those that need a custom route would use it: [YourFilter("CustomError")]
That way your general route is only hardcoded once in the class that it really belongs. Of course for custom error routes you can create some constant strings to clean more the code