3

One of my Web API takes IP address as a URL param (string type) and does something with it. The problem is that I'm not able to pass an IP address as part of the URL.

It's a HTTP GET. A request of http://localhost/app/dosomethingwiththisip/10.20.128.0 fails while http://localhost/app/dosomethingwiththisip/10 succeeds (even though it fails in terms of what needs to be done with it).

Web API method is defined as, with attribute routing enabled,

[Route("dosomethingwiththisip/{ipAddress}")]
[HttpGet]
public bool dosomethingwiththisip(string ipAddress)
{
}

Am I doing something wrong?

Askar Hussain
  • 123
  • 4
  • 11

2 Answers2

3

I finally went with a simple solution of appending a slash character at the end of the URL after the IP address. Thanks to @Pharylon for the tip to a similar question, Dots in URL causes 404 with ASP.NET mvc and IIS

Community
  • 1
  • 1
Askar Hussain
  • 123
  • 4
  • 11
-2

If you are specifying a url parameter and not a file or directory name, then you should prefix your list of parameters with ? so the web server knows. It can't tell what you intended.

Try: http://localhost/app/dosomethingwiththisip/?10.20.128.0

Fuzzy Logic
  • 304
  • 1
  • 9
  • Thanks. A bit better but still an issue with route resolution I guess, {"Message":"No HTTP resource was found that matches the request URI 'http://localhost/app/users/dosomethingwiththisip/?10.20.128.0'.","MessageDetail":"No type was found that matches the controller named 'users'."} – Askar Hussain Feb 26 '15 at 21:10
  • Please learn about ASP.NET MVC's and WebAPI's routing (or URL rewriting/routing in general). – CodeCaster Feb 26 '15 at 21:19
  • URL rewrites are still based on URLS. Broken trickery doesn't change that the webserver was trying to load a page called 10.20.128.0 – Fuzzy Logic Feb 26 '15 at 21:25