Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routes should not register in RouteDirection.UrlGeneration direction #85

Open
rjgotten opened this issue Jun 7, 2016 · 1 comment
Open

Comments

@rjgotten
Copy link

rjgotten commented Jun 7, 2016

The "Elmah.Mvc" and "Elmah.Mvc.Detail" routes registered in the package's Bootstrap currently run for both RouteDirection.IncomingRequest and RouteDirection.UrlGeneration.

These routes should not be used for url generation!

They are registered without any kind of constraint limiting their applicability and thus can match any url generation request from the ASP.NET MVC application into which the Elmah.Mvc package is installed.

There are real-life scenarios in which Elmah.Mvc registers its routes before the application itself and in those particualr cases, the routes from the package will overtake all of the application's routes, causing url generation to completely break down into nonsense: redirecting everything to a /elmah?<query> url, where <query> is a query string containing all the serialized route values that should've been used to matched against one of the application's own routes.

@rjgotten
Copy link
Author

rjgotten commented Mar 6, 2019

Wow... Has it been almost 3 years already without reply?
(Nice...)

Ok then: in the event anyone else runs across this as a problem, and the developers of this package continue to not supply a solution; you can work around it by modifying the routes that the package registers, after the fact:

private static void HotPatchElmahMvc(RouteCollection routes)
{
  Patch(routes["Elmah.Mvc"]);
  Patch(routes["Elmah.Mvc.Detail"]);

  void Patch(RouteBase routeBase)
  {
    if (routeBase is Route route)
    {
      route.Constraints.Add(
        Guid.NewGuid().ToString(),
        new DirectionConstraint(RouteDirection.IncomingRequest)
      );
    }
  }
}

Here DirectionConstraint is a very simple IRouteConstraint that simply returns false on route directions that don't match up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant