0

I'm trying to create an action on a controller which takes a domain-qualified username as an argument.

public class AccountsController : ApiController
{
    [HttpGet, Route("accounts/{username}")]
    public IHttpActionResult Get(string username)
    {
        return Ok();
    }
}

I can perform an HTTP GET /accounts/test%40testing and get the OK response back.

When I try to make a similar request with a qualified username, the action on the controller isn't hit; HTTP GET /accounts/user%40testing.org gets a 404 response. I can see the request entering the application's OWIN middleware, so I'm confident it's making it out of the host into the .NET code.

I'm assuming there's something special about the way Web API handles these values, but I can't find anything in the MSDN documentation or a hint on how to handle this.

How can I get these values passed into the action?

Paul Turner
  • 38,949
  • 15
  • 102
  • 166
  • Possible duplicate of [ApiController returns 404 when ID contains period](http://stackoverflow.com/questions/13298542/apicontroller-returns-404-when-id-contains-period) – Paul Turner Jun 29 '16 at 13:24

1 Answers1

1

Add another route.

[Route("accounts/{username}.{ext}")]

The period is trying to route it to a file if no matching routes are found resulting in a 404. So, you need to explicitly create a route with a period to catch it. Then just have the logic in the method concat the username and ext back together and call you existing logic.

ManOVision
  • 1,853
  • 1
  • 12
  • 14