sam
sam

Reputation: 330

ASP.NET MVC Ignore.Routing issue

When I request the following URL from my MVC application I constantly get redirected to the HomeController.

www.mymvcapp.com/?m=standardvalue&a=someothervalue&code=12345

Now I'm trying to overcome this by edditing the Global.asax.cs request routes, e.g.

routes.IgnoreRoute(".*m=standardvalue.*");

So what I expect as a result is whenever the URL contains "m=standardvalue" it won't take me to the HomeController. It could be I'm doing this totally wrong, someone that can point me in the good direction for solving my problem.

Additional info: The link doesn't look anything like MVC, thats because Apllication Request Routing (IIS7) catches this URL and translates it to a webserver running PHP.

Upvotes: 2

Views: 254

Answers (1)

Loupi
Loupi

Reputation: 701

What you need here is a route constraint. The constraint will return true if the requested URL has no target controller and contains a query string with a variable m that equals standardvalue.

public class DefaultWithoutParamsConstraint : IRouteConstraint
{
    public bool Match(HttpContextBase httpContext,
                      Route route,
                      string parameterName,
                      RouteValueDictionary values,
                      RouteDirection routeDirection)
    {
        return values[parameterName] == null &&
               httpContext.Request.QueryString["m"] == "standardvalue";
    }
}

Now just add this constraint to your ignore list:

routes.IgnoreRoute(
    "{*controller}",
    new { controller = new DefaultWithoutParamsConstraint() }
);

Upvotes: 1

Related Questions