1

I have a Message Handler in my Web API 2 project which change the url to a different path. Such as url "root/controller/somevalue/detials" will be changed to "root/controller/2/details". Where "somevalue" or 2 is a parameter for the action method.

I have placed the message handler registration code before calling config.MapHttpAttributeRoutes(); Message handler is registered as config.MessageHandlers.Add(new MyHandler());

For normal route mapping it is working fine. But if I enable attribute based routing then the message handler is called and changed the url but action method is hit with the same "somevalue" not "2".

What is happening here?

halfer
  • 19,824
  • 17
  • 99
  • 186
Tanjeer
  • 89
  • 4

1 Answers1

0

If you are using RouteAttribute, then you can have Route value like this for capturing somevalue :

Route["details/{somevalue}"]
public IHttpActionResult MyCustiomApiMethod(string somevalue)
{
    //return 
}
Akash KC
  • 16,057
  • 6
  • 39
  • 59
  • Yes, I did exactly what you are pointed out. But the problem is the "somevalue" is encrypted and I am using that message handler to decrypt it. So the some value should be a number after decrypting it. – Tanjeer Jan 21 '17 at 07:45
  • Have you used attribute like above? enclosed variable in parenthesis {} which you want to capture – Akash KC Jan 21 '17 at 07:57
  • OP has the route as `somevalue/details` but your answer has `details/somevalue` (positions swaped) – AsifM Mar 11 '18 at 22:16