0

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.

Sauron
  • 2,156
  • 5
  • 17
  • 20
  • Try this in core 3.1: context.RouteData.Values["culture"]?.ToString(); – LouraQ Feb 26 '20 at 10:13
  • RouteData is ok. When a value is assigned to RouteData automatically HttpContext should get changes by the GetRouteValue, but that not happens in case of core 3. Maybe not best solution, but for now I solved assign my value to HttpContext.Request.RouteValues["culture"] – Sauron Feb 28 '20 at 07:55

0 Answers0