Sauron
Sauron

Reputation: 2346

RouteData not applied to HttpContext only on .NET Core 3

I want to set RouteData but changes are not applied to HttpContext.

public class LocalizeRouteAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        context.RouteData.Values["culture"] = "en";
        string routeCulture = context.HttpContext.GetRouteValue("culture")?.ToString();
        // ON NET CORE 2.2 routeCulture return "en"
        // ON NET CORE 3.1 routeCulture return null

        base.OnActionExecuting(context);
    }
}

Am I missing something new?

To reproduce this case you have to create the filter on a new MVC simple project and apply it to HomeController. It will work on 2.2 but not on 3.1.

Upvotes: 0

Views: 333

Answers (0)

Related Questions