c# - Async RouteBase in ASP.NET with GetRouteDataAsync and GetVirtualPathAsync? -
i have custom asp.net route has io operations in it. now, assume these io operations can't cached (i.e. big).
in way i'm looking asyncroutebase
class with
public async override task<routedata> getroutedataasync(httpcontextbase httpcontext) public async override task<virtualpathdata> getvirtualpathasync(requestcontext requestcontext, routevaluedictionary routevalues);
- does similar exist? (can't find it)
- is there place within asp.net pipeline can create myself?
i'm using asp.net mvc 5.2.3.0
you cannot create asyncroutebase, because routes used asp.net mvc synchronous. have understand in order create async methods, must consume them asynchronously, can't magically make asynchronous adding async method.
routing can't asynchronous various reasons, routes cached , created once @ time of executing first request. beware, routes cached, not change , can't changed in runtime because executed first, if routing make async db calls, every request have wait routing condition fulfill slow down entire application.
and not need asyncroutebase, instead can create async route handler.
public class asyncroutehandler : iroutehandler { ihttphandler iroutehandler.gethttphandler(requestcontext requestcontext) { return new asynchttphandler(); } } public class asynchttphandler : httptaskasynchandler{ public override async task processrequestasync(httpcontext context) { } }
however, using mvc pipeline inside require lots of work, can ignore , service response here. can use controller factory inside , create methods execute need.
other alternative use mef or other form of di manage larger code base , invoke respective methods inside asynchttphandler.
Comments
Post a Comment