I have a small problem with ASP.NET and MVC5 (I am beginning with MVC.NET). Until yesterday, everything worked great! But today, I don't know why, I have problems with "Custom routes Annotations".
I have a Controler "Prodouits" with this Action :
[Route("{culture}/Produits/{nom_groupe}/{nom}-{id}")]
public ActionResult Detail(string nom_groupe, string nom, string id)
{
// ...
return View();
}
In my views, when I call "Url.Action(...)", the URL is good. But when I go on the page, RouteData seems to be bad (RouteData are not restored correctly).
Look at my RouteData : Keys[0] => "MS_DirectRouteMatches" Keys[1] => "controller"
Values[0] => //A list of only 1 RouteData with my 6 parameters into it...
Values[1] => Produits
If I delete my "Custom Route Annontation", everything works great but the URL is very sad...
Does someone have an idea about the problem and the solution ? Thanks all for help!
EDIT: More information about the problem. I have a "BaseController" for the language. I override the "BeginExecuteCore" method. There is the code :
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
{
string cultureName = RouteData.Values["culture"] as string;
// Attempt to read the culture cookie from Request
if (cultureName == null)
cultureName = Request.UserLanguages != null && Request.UserLanguages.Length > 0 ? Request.UserLanguages[0] : null; // obtain it from HTTP header AcceptLanguages
// Validate culture name
cultureName = CultureHelper.GetImplementedCulture(cultureName); // This is safe
if (RouteData.Values["culture"] as string != cultureName)
{
// Force a valid culture in the URL
RouteData.Values["culture"] = cultureName.ToLowerInvariant(); // lower case too
// Redirect user
Response.RedirectToRoute(RouteData.Values);
}
// Modify current thread's cultures
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
return base.BeginExecuteCore(callback, state);
}
Thank you for help :-)
EDIT: Nobody has a solution? Thank you again!