How to define a DelegatingHandler for custom route?

I've created a DelegatingHandler and it works for every request. I've read some articles that i can define a handler for a specific route but I've tried a lot of ways without success, i'm missing something that i didn't found what is.

The last attempt was:

GlobalConfiguration.Configuration.Routes.MapHttpRoute( name: "SaveMessage", routeTemplate: "api/message/{type}", defaults: new { type = RouteParameter.Optional }, constraints: null, handler: HttpClientFactory.CreatePipeline( new HttpControllerDispatcher(GlobalConfiguration.Configuration), new DelegatingHandler[]{new ValidationHandler()}) );

My class Controller and method has the follow attributes:

[RoutePrefix("api/message")] public class MessageController : ApiController { [Route("{type}")] [HttpPost] public HttpResponseMessage Save(string type, [FromBody] Message message) { .... } }

What is missing to my handler only works on requests like api/message/text?

I've read links like How to make more MapHttpRoutes for MVC 4 Api and

-------------Problems Reply------------

The issue is the constraints that is set to null. You should define it like this for making it work for POST or GET:

constraints: new { httpMethod = new System.Web.Http.Routing.HttpMethodConstraint(HttpMethod.Post) }

Category:c# Views:2 Time:2018-11-07

Related post

  • How to define default "TagPrefix" for custom controls 2008-10-24

    I have a number of custom controls that I am trying to enable designer support for. The signature looks something like the following: [ToolboxData("<{0}:MyDropDownList runat=\"server\" CustomProp="123"></{0}:MyDropDownList>")] public clas

  • How to write rspec test for custom routes 2012-02-06

    I have the following custom route: match '/boeing-737', controller: :planes, action: :display, id: 1000 The 'get' method in rspec only accepts action name, but doing this: get :display, id: 1000 I am getting: RoutingError: No route matches {:id=>"

  • how to define rails 3.1 custom routes 2011-10-14

    I want to route http://localhost:3000/users/1/rename/alex to my users controller with rename action. what I did was: match 'users/:id/rename/:name' => 'users#rename', but this is not working, the part after 'users/:id/' is not mapped at all, since

  • how to define short key for scroll in form in c# 2010-10-13

    how to define short key for scroll in form in c# --------------Solutions------------- The default keys for scrolling are the arrows. If you want to redefine them with new keys, you can override your control's ProcessCmdKey method and use the arrows w

  • How jquery define click function for get parameter inside anonymous function? 2011-04-25

    I dont understand javascript syntax well,my question: How jquery define click function for get parameter inside anonymous function? The Case: $("a").click(function(event) { alert(event.type); }); in C the function should be defined: void click(fn,eve

  • How to define different style for same layout according to screen size? 2012-02-22

    How to define different style for same layout according to screen size. Is there any way to define such thing, except from different layout folder for different screen size. --------------Solutions------------- I haven't found any other way to suppor

  • How to overwrite :path_names for custom routes 2011-10-26

    I've implemented RESTFUL routes in english but the application is for german users so the routes should be renamed to german. I did this using the :path_names option and for the CRUD routes but this doesnt work for the routes I created on my own. For

  • How to configure reverse proxy/loadbalancer for custom routing 2010-10-13

    Suppose I have 3 webservers behind a reverse proxy/loadbalancer. Currently I use Apache 2 but don't mind switching. Those webservers are not equal. They have different sets of local data meaning that different kinds of requests will be handled more e

  • WPF XAML Intellisense doesn't work correctly for custom routed event handlers 2009-12-07

    I defined a custom routed event with the following constructs (names changed): public class MyRoutedEventArgs : RoutedEventArgs {...} public delegate void MyRoutedEventHandler(Object sender, MyRoutedEventArgs args); public static readonly RoutedEvent

  • How to define a grammar for a programming language 2010-02-23

    How to define a grammar (context-free) for a new programming language (imperative programming language) that you want to design from scratch. In other words: How do you proceed when you want to create a new programming language from scratch. --------

  • How can I setup a simple custom route using Zend Framework? 2010-04-13

    I'm looking to setup a custom route which supplies implicit parameter names to a Zend_Application. Essentially, I have an incoming URL which looks like this: /StandardSystems/Dell/LatitudeE6500 I'd like that to be mapped to the StandardsystemsControl

  • How to create quickhelp entry for custom functions in Xcode 2010-08-18

    I still searched for this but without success. I would like to create 'Quick Help' entries in XCode for custom classes. Don't know Quick Help? Select a function-name, right-click and choose 'Quick Help' Then you can see function-description, etc. Som

  • How to define parameter names for higher order functions in C# 2010-10-28

    In C# it is possible to create higher order functions, ie. functions g taking functions as arguments. Say I want to create such a function which given a function f and returns another function extending its functionality. How do I define argument nam

  • creating a link_to for custom route 2010-11-29

    I have a custom route (if I am doing that correctly, this is the first time I have done this) that looks like this: map.connect 'purchases/type/:type', :controller => 'purchases', :action => 'index' so I want to create a link_to that would use

  • How to define programming language for the `` element 2011-01-26

    How do I define programming language for the <code> element in XmlDocs? I'm having XML examples, but they are highlighted as C# (since it's a C# project). Example: /// <code> /// <![CDATA[ /// <SaveConfig> /// <File>Web.con

  • How to define streaming operator for boost::spirit::qi and std::list container 2011-03-13

    In one of my rules a have qi::locals<> with stl container as parameter. When I compile my program without BOOST_SPIRIT_QI_DEBUG, everything works fine. But when I turn BOOST_SPIRIT_QI_DEBUG on, program can't be compiled because of missing opera

  • how to set image view for custom title bar in android 2011-05-02

    I want to set custom title bar to which i want to set ImageView as background to the title bar. how to set ImageView for custom title bar in android. i used: getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.page_layout); requestwindowf

  • how to define seperate layouts for Motorola Atrix and Motorola Droid 2011-05-03

    Hi I need to define separate layout's for Motorola Droid and Motorola Atrix .I tried with drawable-hdpi and layout-long ,layout-large-long but both seems to relay on layout-long .How to define a separate layout's supporting both device.Hence the layo

  • How to define the Principle for an AWS Policy Statement 2011-06-08

    I'm starting from to create a policy that will grant upload rights to a specific S3 bucket for a list of users. I'm not clear on how i define who those users should be. The docs refer to Principle a

  • How to define an icon for my context menu item? 2011-07-10

    How can I define an icon for a context menu item without declaring it in manifest.json? For example I want to offer the possibility to change the icon in the options. I thought I could use something like that, but nothing found in the Docs:

  • How to define table aliases for joined tables in plain SQL queries? 2011-07-18

    I have an entity that is mapped with a <join> element like this: <class name="Entity" table="Entites"> <id name="Id"> <generator class="guid" /> </id> <property name="SomeProperty" /> <join table="EntityData" op

  • How to define scala type for no argument function? 2011-08-29

    This works def func(f: => Int) = f This dosn't (inside class for example) type EmptyFunct = => Int or type EmptyFunct = (=> Int) Scala version 2.9 Two questions: Why dosn't syntax sugar work in second case? How to define this function withou

  • How to set the texttype for custom textview in xcode 2012-01-19

    How to give the style for the custom textview as password in xcode ios4.3 --------------Solutions------------- I think this is what you are looking for UITextField *textFieldPassword = [[UITextField alloc] initWithFrame:CGRectMake(120, 90, 150, 30)];

  • How to define an id for the added rows in a table in JS? 2012-01-26

    i have to add rows to a table dynamically,i can add rows and delete.But how can i define an id for the added rows to write something inside of them or add some links ? --------------Solutions------------- If it is always the last row, your could use

  • How to use stdext::hash_set for custom type in VC++ 2010? 2012-03-09

    I want to use stdext::hash_set for custom type. In fact I realized how to do so, but I am not sure if it is correcly (it is compilable, but looks somewhat dirty). The code follows: // This is my custom type struct Point { Point(int _x, int _y, int _z

Copyright (C), All Rights Reserved.

processed in 0.129 (s). 11 q(s)