0

I am trying to get a resource by providing ip address in GET request.

/api/computers/ip/192.168.10.90 - throws 404 error

/api/computers/ip/192~168~10~90 - hits the method

It looks like providing the IP is the issue here. So how do I pass IP as part of GET request?

Gopi
  • 5,656
  • 22
  • 80
  • 146

2 Answers2

0

One way to do this is to encode the ip address and pass it as a querystring value. Your method will be

[Route("computers/ip")]
public IHttpActionResult GetComputer(string ip)

And you send the request : .../computers/ip?ip=[theEncodedIP]

You can remove the /ip from the method Route

[Route("computers")]
public IHttpActionResult GetComputer(string ip)

And you send the request using : .../computers?ip=[theEncodedIP]

Jek
  • 441
  • 7
  • 16
0

You have to pass ip in encoded form, but in querystring in Get request. You can do this by HTTP handlers also, so if request matches the criteria you can use your logic before request goes to the server.

Some links have suggested to set runAllManagedModulesForAllRequests true in Web.Config.

<modules runAllManagedModulesForAllRequests="true">

Enabling RunAllManagedModulesForAllRequests will enable all managed modules for all requests. So resources like images, PDFs and everything else will be processed by server when they don't need to be.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197