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

Order of route values shouldn't impact key built #65

Open
jonathanjto opened this issue Feb 14, 2018 · 1 comment
Open

Order of route values shouldn't impact key built #65

jonathanjto opened this issue Feb 14, 2018 · 1 comment

Comments

@jonathanjto
Copy link

jonathanjto commented Feb 14, 2018

Hi,

When manipulating items using the methods of the OutputCacheManager, RemoveItem for example.

The order of the "RouteValues" should not be important.

Just add "OrderBy" key to this code in the KeyBuilder class for the method
public string BuildKey(string controllerName, string actionName, RouteValueDictionary routeValues)


            if (routeValues != null)
            {
                foreach (var routeValue in routeValues.OrderBy(c => c.Key))
                {
                    builder.Append(BuildKeyFragment(routeValue));
                }
            }


Best regards

@jonathanjto
Copy link
Author

jonathanjto commented Feb 15, 2018

// Same here, if no value in params - don't use it in the key (area empty or not specified should be the same key fragment)

        public string BuildKeyFragment(KeyValuePair<string, object> routeValue)
        {
            var value = routeValue.Value?.ToString().ToLowerInvariant() ?? "<null>";
            if (!string.IsNullOrWhiteSpace(value))
            {
                return string.Format("{0}={1}#", routeValue.Key.ToLowerInvariant(), value);
            }
            return "";
        }

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