2

I have done some looking around and not stumbled onto anything resembling the issue I am experiencing so I thought I would throw it up here and see what, if anything sticks.

I have a controller and method set up.

public class BoothAPIController : ITApiControllerBase
{
    [HttpGet]
    public HttpResponseMessage GetActiveAssetNumbersLike([FromUri] String id)
    {
        HttpResponseMessage ret;

        // ... do some processing

        return ret;
    }
}

The routes are set up in Global.asax

protected void Application_Start(object sender, EventArgs e)
{

    GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "CustomApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional });


    GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "BoothWithDateAPI",
            routeTemplate: "api/{controller}/{boothID}/{year}/{month}/{day}");

    GlobalConfiguration.Configuration.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional });

}

And these two requests execute flawlessly ...

http://localhost:52211/api/BoothAPI/GetActiveAssetNumbersLike/PR
http://localhost:52211/api/BoothAPI/GetActiveAssetNumbersLike/PRN0

This one however ... returns a 404 error ...

http://localhost:52211/api/BoothAPI/GetActiveAssetNumbersLike/PRN

The Header for the failed request looks like ...

Cache-Control →private
Content-Length →2879
Content-Type →text/html; charset=utf-8
Date →Mon, 29 Aug 2016 12:53:08 GMT
Server →Microsoft-IIS/8.0
X-AspNet-Version →4.0.30319
X-Powered-By →ASP.NET
X-SourceFiles →= [string]

While the successful requests look like

Cache-Control →no-cache
Content-Length →7731
Content-Type →application/json; charset=utf-8
Date →Mon, 29 Aug 2016 13:13:43 GMT
Expires →-1
Pragma →no-cache
Server →Microsoft-IIS/8.0
X-AspNet-Version →4.0.30319
X-Powered-By →ASP.NET
X-SourceFiles → [string]

(Shrugs) I dunno ... I am at a complete loss why the one change in the parameter makes a difference.

3
  • I see a difference on the Content-Type. When it fails, it is sending a text/html. How are you sending these requests? Via a application, or maybe via Postman?
    – jpgrassi
    Commented Aug 29, 2016 at 14:06
  • Also, why are you setting the routes in Global.asax? Don't you have a WebApiConfig file on your App_Start folder?
    – jpgrassi
    Commented Aug 29, 2016 at 14:09
  • The request is identical and being sent from Postman, only the parameter string is different. As far as the Global.asax ... for the moment convenience. I don't have a lot of configuration going on so there was no need to break it out. As the application grows we may refactor it a bit. Commented Aug 30, 2016 at 12:36

1 Answer 1

2

I did a little digging on this and was surprised myself. Turn out that the parameter you are trying to send PRN is a reserved word in MS-DOS Device Driver

Below is a list of default device driver names.

PRN System list device, usually a parallel port

This question has an answer to the problem: IIS gives 404 when MS-DOS reserved names are used in parameters values

But you should be aware of the potentials pitfalls in setting RelaxedUrlToFileSystemMapping to true. See this article by Scott Hanselman: Experiments in Wackiness: Allowing percents, angle-brackets, and other naughty things in the ASP.NET/IIS Request URL

2
  • Thank you sir! This solved the problem, although I can't imagine why these reserved names have ANYTHING to do with web services ... Commented Aug 30, 2016 at 12:41
  • They are related to the File system. The links I provided explain in details why's that. One thing to learn everyday!
    – jpgrassi
    Commented Aug 30, 2016 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.