0

I have been having issues setting up my custom WebApi route in C#. I am setting up a custom route that uses a company name a parameter. The route works fine, unless the company name ends with a "." I have tried setting double escape but keep getting a 404 error.

Route

config.Routes.MapHttpRoute(
            name: "Contracts",
            routeTemplate:"{company}/Contracts/{action}/{id}",
            defaults: new {controller= "Contracts", id= RouteParameter.Optional}

            );

Controller

 public class ContractsController : ApiController
{
    [HttpGet, ActionName("PrivacyStatements")]
    public HttpResponseMessage GetPrivacyStatements(string Company)
    {
        //code for privacy statements
    }

These will work:

http://localhost/Company%20Name/Contracts/PrivacyStatements

http://localhost/Company.%20Name/Contracts/PrivacyStatements

http://localhost/Contracts/PrivacyStatements?Company=Company%20Name%20Inc.

This does not work:

http://localhost/Company%20Name%20Inc./Contracts/PrivacyStatements

the "." before the "/" in "/Company Name Inc./" always gives me a 404.

Any help is appreciated.

Ted
  • 1
  • https://stackoverflow.com/questions/20998816/dot-character-in-mvc-web-api-2-for-request-such-as-api-people-staff-45287 – m5c May 21 '20 at 22:37
  • Thanks, but this did not resolve my issue. Looking at the post this is when the parameter is at the end and the route is treating it like a file extension instead of a parameter. This is not the case for me since the calls work if the period is not at the end. – Ted May 22 '20 at 13:30

0 Answers0