ASP.NET WebApi how to route the controller to a different name -
have basic thing - need expose post api such mobile/api/pswdrec wanna bind passwordcontroller avoid dull name.
it's webapi areas , i'm trying both attribute routing , maphttproute
. neither works far.
public class passwordcontroller : mobileapicontrollerbase { //[route("api/mobile/pswdrec/")] public restresponsemessage post(usercredentialsmodel credentials) { return restresponsemessage.ok(); } }
checked client side , requests proper json requests. it's starting work when change name of controller pswdreccontroller
.
is there other way "rename" controller?
working on mvc years stuck on simple issue :) helping out ;)
edit:
public class mobileapiarearegistration : arearegistration { private static iwindsorcontainer _container = new windsorcontainer(); public override string areaname { { return "mobileapi"; } } public override void registerarea(arearegistrationcontext context) { context.routes.maphttproute( name: "mobileapidefault", routetemplate: "api/mobile/{controller}/{id}", defaults: new { controller = "expenses", id = routeparameter.optional } ); } public static void setupwebapi(httpconfiguration configuration) {/* javascript serizlizer setup */} } public static class webapiconfig { public static void register(httpconfiguration config) { mobileapiarearegistration.setupwebapi(config); } public static void setupwindsorcontainer(iwindsorcontainer container) { mobileapiarearegistration.setupwindsorcontainer(container); webapiarearegistration.setupwindsorcontainer(container); } } public class webapiapplication : httpapplication { private static readonly iwindsorcontainer _container = new windsorcontainer(); protected void application_start() { arearegistration.registerallareas(); globalconfiguration.configure(webapiconfig.register); filterconfig.registerglobalfilters(globalfilters.filters); routeconfig.registerroutes(routetable.routes); bundleconfig.registerbundles(bundletable.bundles); initializewindsorcontainer(); //initializeexceptionfilters(); } }
nothing special can't make work. when use original names of controllers it's shinning star :)
solution: well, problem in precedence of routers, config "api/mobile/pswdrec/{id}" should've been placed before default router. still can't working attribute routing.
you scenario should work attribute routing without having changing name pswdreccontroller
. sure using route attribute system.web.http
namespace?
Comments
Post a Comment