0

I have a WebAPI method to retrieve some user details based on an Windows Logon:

[Route("api/user/{username}/details")]
public IHttpActionResult(string username)
{
    // ...
}

Suppose I am user arjan on the MYCORP domain, then some javascript on my webpage would issue a GET to http://myserver/api/user/MYCORP\arjan/details.

This route never gets correctly resolved, as IIS, ASP.NET or something will rewrite the \ to a / before routing.

I can see in Fiddler that the correct URL is requested, but errorpage returned from IIS, clearly states it didn't find http://myserver/api/user/MYCORP\arjan/details.

I'm using MVC 5/.NET 4.5/IIS 7.5/VS2015/Windows 7.

So: why is my webserver turning the request URI

http://myserver/api/user/MYCORP\arjan/details

Into

http://myserver/api/user/MYCORP/arjan/details

And how can I turn it off?

Percent-encoding the \ to %5C doesn't resolve the issue, the decoding seems to happen very early at the server.

Note that this is not a duplicate of Route parameter with slash "/" in URL, which asks about using / as a URL parameter. This question is about why IIS/ASP.NET changes \ to /.

Community
  • 1
  • 1
Arjan Einbu
  • 13,543
  • 2
  • 56
  • 59

1 Answers1

1

One workaroud would be to change the route/method signature to

[Route("api/user/{domain}/{username}/details")]
public IHttpActionResult(string domain, string username)
{
    // ...
}

as this would correctly handle the incomming request...

Arjan Einbu
  • 13,543
  • 2
  • 56
  • 59