0

If I create a simple controller in ASP.NET Web API like this:

[RoutePrefix("values")]
public class ValuesController : ApiController
{
    [Route("{value}")]
    public string Get(string value)
    {
        return value;
    }

}

Performing a get on /values/nul returns a 404 page on IIS and IIS express. Also /values/nul.be returns 404. A breakpoint in the controller is never hit in this case, so the request is terminated before it reaches the controller's logic. Is there a work around for this or is this a bug in ASP.NET Web API?

Sven Schelfaut
  • 522
  • 1
  • 7
  • 18
  • Did you try just to access "/values", without "null"? – Kadaj Jan 17 '17 at 09:12
  • It is nul (this is not a typo!) that I mean, not null (passing null is not a problem). Just try it yourself! – Sven Schelfaut Jan 17 '17 at 09:18
  • Can you post the full URL of the request? – genichm Jan 17 '17 at 09:22
  • If IIS express runs on port 52158, the request would be `http://localhost:52158/values/nul` – Sven Schelfaut Jan 17 '17 at 09:25
  • it may be like `http://localhost:61709/api/values/nul` – Pranav Patel Jan 17 '17 at 09:28
  • Well, `http://localhost:52158/values/bla` works and any other valid url parameter does too, I know how Web API works :) – Sven Schelfaut Jan 17 '17 at 09:35
  • 1
    @SvenSchelfaut take a look at http://stackoverflow.com/a/13406807/4045532 – Corporalis Jan 17 '17 at 09:58
  • Thx @Corporalis, setting `relaxedUrlToFileSystemMapping` to `true` solved the issue! – Sven Schelfaut Jan 17 '17 at 10:14
  • Why didn't you said to him: "Thank you man, can you put your comment into answer so I can accept it and help future visitors while thanking you as well in form of SO points"? – Kadaj Jan 17 '17 at 12:03
  • Interesting case! Looking around, this might have to do with the fact that Url's are checked with the same rules as (Windows) file paths. And `NUL` is a device file that returns no data (https://en.wikipedia.org/wiki/Device_file#DOS.2C_TOS.2C_OS.2F2.2C_and_Windows) (also http://superuser.com/questions/317577/why-inputting-nul-in-windows-cmd-gives-a-certain-error-message). Just a guess though. – Peter Jan 18 '17 at 12:16

0 Answers0