asp.net mvc 4 - MVC4 Get Route Data From ApiController -


i'm looking grab {contract} value out of route when hit api controller.

config.routes.maphttproute(             name: "defaultapi",             routetemplate: "api/{contract}/{controller}/{id}",             defaults: new { id = routeparameter.optional }         ); 

so when user hits /api/rearch/allergies/1234 i'd grab "rearch" , use fetch connection string.

i've attempted using routedata , routetable below no luck:

this.routedata.values["contract"].tostring()  routetable.routes["contract"] 

is there i'm missing? different in apicontroller?

thanks in advance!

you can grab out of method's parameters... if can change those:

[httppost] [actionname("actionname_ifdifferentthanmethodname")] public httpresonsemessage method(string contract, int id) {   string connectionstring = system.configuration.configurationmanager.connectionstrings[contract]; } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -