1

Closed

UrilHelper's link generation should be case IN-sensitive when taking in tokens

description

Following is the inconsistent experience currently.

Scenario1

I have the following route(NOTE: the route tokens are all in CAPS...more realistic scenario is when users say 'Controller'...note the capital 'C'):
config.Routes.MapHttpRoute("Default", "{controller}/{action}/{id}", new { CONTROLLER = "SampleTests", ACTION = "GetString1", id = RouteParameter.Optional });

When i make a request like this : "http://localhost:9090/", it properly delivers it to the "SampleTests" controller's "GetString1" action.

Scenario2

I am trying to generate a link at an ApiController's action. The route through which i arrived at the action is:
"http://localhost:9090/SampleTests/GetString2" Doing the following at the action(NOTE: the route tokens are all in CAPS): Url.Link("Default", new { CONTROLLER = "Greetings", ACTION = "SayHello" });

Expected:"http://localhost:9090/Greetings/SayHello" Actual :"http://localhost:9090/SampleTests/GetString2" Observation: in the incoming path we are not considering the case-sensitiveness of the route tokens, but during Url Link generation we are.

file attachments

Closed May 22 at 11:40 PM by kichalla
Verified

comments

kichalla wrote Oct 4, 2012 at 1:58 AM

Attached a standalone repro

HongmeiG wrote Oct 4, 2012 at 10:31 PM

This is a bug in the Url.Link logic.

HongmeiG wrote Mar 26 at 4:45 AM

it only repros in self host. Kiran has found the bug, and it is in HttpRoute class.

private static IDictionary<string, object> GetRouteDictionaryWithoutHttpRouteKey(IDictionary<string, object> routeValues)
    {
        var newRouteValues = new Dictionary<string, object>();
        if (routeValues != null)
        {
            foreach (var routeValue in routeValues)
            {
                if (!String.Equals(routeValue.Key, HttpRouteKey, StringComparison.OrdinalIgnoreCase))
                {
                    newRouteValues.Add(routeValue.Key, routeValue.Value);
                }
            }
        }
        return newRouteValues;
    }