c# - How to distinguish between a query string variable and a URL segment variable with Web API 2.0 attribute routing? -


lets have following apicontroller , method:

[routeprefix("configs")] public class fullconfigcontroller : apicontroller {     [route("{id}")]     [httpget]     public string getconfig(guid id)     {         return "my config data";     } } 

it's simple method designed return basic configuration data based on configurations id represented guid. intention call end point such

http://<url>/configs/70c55eda-9671-4d75-a715-0835db8ac2e3

however not route through engine. yet this

http://<url>/configs?id=70c55eda-9671-4d75-a715-0835db8ac2e3

does. how specify not want query string parameter here url segment parameter instead?

edit: request webapiconfig

public class routetemplatevariables {     public const string pluginroot = "pluginroot";     public const string corepluginroot = "corepluginroot";     public const string additionalsegments = "additionalsegments"; }  public static class webapiconfig {     private static readonly log4net.ilog log = log4net.logmanager.getlogger(system.reflection.methodbase.getcurrentmethod().declaringtype);      public static void register(httpconfiguration config)     {         log.info("webapiconfig.register()");          // attribute routing         config.maphttpattributeroutes();          // convention-based routing.         config.routes.maphttproute(             name: "pluginapi",             routetemplate: "api/plugin/{" + routetemplatevariables.pluginroot + "}/{*" + routetemplatevariables.additionalsegments + "}",             defaults: new { additionalsegments = routeparameter.optional }         );          config.routes.maphttproute(             name: "coreapi",             routetemplate: "api/{" + routetemplatevariables.corepluginroot + "}/{*" + routetemplatevariables.additionalsegments + "}",             defaults: new { additionalsegments = routeparameter.optional }         );     } } 


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -