c# - Owin Custom Routing MIddleware in ASP.NET Web Api 2.0 -
i have started building asp.net web api 2.0 application using owin middleware microsoft (http://owin.org/). have several questions related routing can't find great tutorial on web api. have customers potentially have several companies (databases, essentially) want service through web api. wanted user able specify company through custom route. example, route api/mycompany/products load of products mycompany. obviously, not want pass company name every action on every controller, want create custom route or custom routing middleware if standard routing won't work.
1) there tutorials on routing web api can me understand doing , how should doing things?
2) there tutorials building middleware on owin routing? in general?
3) recommendations on better way this, if there one.
the companies necessary because don't want hard code web.config file. basically, app have info on of companies and, using route, metadata such related connection string.
any advice great! know isn't usual post had no idea look. haven't found of use via standard means (google , msdn) unless overlooking simple concept.
have tried looking attribute routing in asp.net web api 2
which allow set route prefix on controller satisfy looking for.
[routeprefix("api/{companyname}")] public class customercontroller : apicontroller { // api/mycompany/products [route("products")] public ienumerable<product> getproducts(string companyname) { ... } // api/mycompany/orders [route("orders")] public ienumerable<order> getorders(string companyname) { ... } .... }
if read through mentioned link see how set , use needed.
Comments
Post a Comment