Thursday 15 April 2010

asp.net mvc 5 - Attribute Routing with BaseClass implementation: Correcltly listed but still fails -



asp.net mvc 5 - Attribute Routing with BaseClass implementation: Correcltly listed but still fails -

i've set attribute routing on controller class inherits base of operations class handle i18n civilization set/selection logic (as described in article asp.net mvc 5 internationalization) process fails, although route seemed set correctly.

[routeprefix("{culture}")] public class homecontroller : basecontroller { public actionresult index() { homecoming view(); } [route("hakkimda")] public actionresult about() { viewbag.message = "your application description page."; homecoming view(); }

when seek link see gray screen of death on browser on address bar:

http://localhost:53530/tr-tr/hakkimda?ms_directroutematches=system.collections.generic.list%601%5bsystem.web.routing.routedata%5d

i believe problem way base of operations controller implements i18n logic based on beginexecutecore overloading.

protected override iasyncresult beginexecutecore(asynccallback callback, object state) { string culturename = routedata.values["culture"] string; // effort read civilization cookie request if (culturename == null) culturename = request.userlanguages != null && request.userlanguages.length > 0 ? request.userlanguages[0] : null; // obtain http header acceptlanguages // validate civilization name culturename = culturehelper.getimplementedculture(culturename); // safe if (routedata.values["culture"] string != culturename) { // forcefulness valid civilization in url routedata.values["culture"] = culturename.tolowerinvariant(); // lower case // 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; homecoming base.beginexecutecore(callback, state); }

probably execution precedence of beginexecutecore , routing have mismatch knowledge on both don't suffice solve it.

i've seen article(what’s new in asp.net mvc 5.2 : attribute routing improvements) illustration provided there bit different , because it's new there aren't other examples on net.

mr-anton's reply stop getting rubbish in address bar it'll stop language changing.

i had issue after alter mvc5 mvc5.2 this reply says microsoft issue

the workaround see if route info in nested route key

var routedata = routedata; if (routedata.values.containskey("ms_directroutematches")) { routedata = ((ienumerable<system.web.routing.routedata>)routedata.values["ms_directroutematches"]).first(); } string culturename = routedata.values["culture"] string;

and works.

asp.net-mvc-5 asp.net-mvc-routing

No comments:

Post a Comment