Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core API Request does not match a supported file type

I just want to make sure I have no issue here. Does anybody know what causes the

2017-03-17 07:59:17.5838|1|Microsoft.AspNetCore.Hosting.Internal.WebHost|INFO|Request starting HTTP/1.1 GET http://192.168.20.57:8081/hardware/configuration/active application/json  
2017-03-17 07:59:17.5868|4|Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware|DEBUG|The request path /hardware/configuration/active does not match a supported file type

I'm exposing the Web API by Kestrel only (no IISIntegration).

The request header contains

GET /hardware/configuration/active HTTP/1.1
Accept: application/json, text/plain, */*
Content-Type: application/json

Defining [Produces("application/json")] explicitly in my controller has no effect.

like image 610
marrrschine Avatar asked Mar 17 '17 07:03

marrrschine


2 Answers

Set StaticFileOptions.ServeUnknownFileTypes to true:

        app.UseStaticFiles(new StaticFileOptions()
        {
            FileProvider = new PhysicalFileProvider("mypath"),
            ServeUnknownFileTypes = true // <<<<<<
        });

or find out where the unknown types can be extended (please let me know in the latter case).

like image 120
citykid Avatar answered Nov 19 '22 21:11

citykid


After the request comes in by kestrel (which is your first log row).

It first goes through a middleware pipeline until it reaches the WebApi middleware.

As you can see in the second logging row: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware. It reached the StaticFileMiddleware and not the WebApi Middleware.

Probably the staticFileHandler finds a file there in the wwwroot folder and thus returns this message? Or Even before it tries to check the filesystem it checks if it is an allowed/known file extension and this is not the case, thus this second log message.

like image 43
Joel Harkes Avatar answered Nov 19 '22 21:11

Joel Harkes