Why do my requests with file extensions return 404 if slash is omitted before Query Identifier?

Steven Swan

We have a web API service running that uses attribute routing. When a request is sent with the route not containing a file extension it routes to the correct action evaluating the query string correctly. When we have a route that contains a file extension if you do not include a '/' before the query identifier then you get a 404 Not Found.

For example:

Working:

https://example/api/interview/test/70ac327a-d77b-41da-bf9c-76af8efdfbbaf/Test.docx/?format=Unspecified

Not Found:

https://example/api/interview/test/70ac327a-d77b-41da-bf9c-76af8efdfbbaf/Test.docx?format=Unspecified

It is probably also worth noting that the route parameter with the file extension is optional.

An example route is:

[HttpPost]
[Route("api/HDCS/Interview/{subscriberId}/{packageId}/{templatename?}")]
public IHttpActionResult Interview(string subscriberId, string packageId, string format = null,
    [FromUri] IEnumerable<string> markedVariables = null, string templatename = null,
    bool encodeFileNames = false, string retrieveFromHub = null){...}

Edit:

Sorry I also should have mentioned that we have

<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>

in our web.config

Steven Swan

I didn't include one very important piece of information when explaining our API which was needed when fixing this issue. We are using OWIN and to ensure that the OWIN module actually passes the URL's with extensions in the route onto WebApi we had to add to our Startup.cs file:

        builder.UseWebApi(config);
        builder.UseStageMarker(PipelineStage.MapHandler); // this line

This has resolved the issue and we no longer get 404's when using the route detailed in the question.

Source for fix: https://github.com/domaindrivendev/Swashbuckle/issues/57

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why do my requests with file extensions return 404 if slash is omitted before Query Identifier?

From Dev

Why does my Angular POST request for PHP file return 404?

From Dev

Why are the angle brackets before the return type omitted sometimes from the definition of a generic method

From Dev

Global alias for all files in a directory, by their file names (extensions, if available will be omitted)

From Dev

Git not ignoring some files extensions in my .gitignore file. Why?

From Dev

URL is appending forward slash '/' before query string

From Dev

Why does my WebClient return a 404 error most of the time, but not always?

From Dev

Why my first load data axios is return 404 Vue Js?

From Dev

Why does nginx return 404 on my Kubernetes Ingress route?

From Dev

Why do the author use a tilde before file?

From Java

Why do my conditions (IF statements) return false?

From Dev

Why do my PrePersist and PreUpdate return null?

From Dev

Why does stripslashes not return the data without a slash?

From Dev

Web Requests do not use same session identifier

From Dev

Web Requests do not use same session identifier

From Dev

Creating File Extensions for my application

From Dev

Why do my WebAPI RESTful routes throw 404 errors?

From Dev

Windows- how do I create my own file extensions, and associate them with my own program?

From Java

Why does my DNS MX query return an SOA record?

From Dev

Why does my db query return zero(no data) in the required coloumns

From Dev

Why does CodeIgniter return my SQL query as an array, with an object inside?

From Dev

Why does my Firebase query return the wrong order?

From Dev

Why does my mysql query always return an empty result?

From Dev

Why using two variable causes my query to return with no row

From Dev

Why wont TO_DATE return the TIME section of my query?

From Dev

Why does my LINQ query always return 0?

From Dev

Why does my SQL query return no rows, when sum is 0

From Dev

Lumen GET Requests Return 404 Error

From Dev

Why do my WinForm controls flicker before the paint event?

Related Related

  1. 1

    Why do my requests with file extensions return 404 if slash is omitted before Query Identifier?

  2. 2

    Why does my Angular POST request for PHP file return 404?

  3. 3

    Why are the angle brackets before the return type omitted sometimes from the definition of a generic method

  4. 4

    Global alias for all files in a directory, by their file names (extensions, if available will be omitted)

  5. 5

    Git not ignoring some files extensions in my .gitignore file. Why?

  6. 6

    URL is appending forward slash '/' before query string

  7. 7

    Why does my WebClient return a 404 error most of the time, but not always?

  8. 8

    Why my first load data axios is return 404 Vue Js?

  9. 9

    Why does nginx return 404 on my Kubernetes Ingress route?

  10. 10

    Why do the author use a tilde before file?

  11. 11

    Why do my conditions (IF statements) return false?

  12. 12

    Why do my PrePersist and PreUpdate return null?

  13. 13

    Why does stripslashes not return the data without a slash?

  14. 14

    Web Requests do not use same session identifier

  15. 15

    Web Requests do not use same session identifier

  16. 16

    Creating File Extensions for my application

  17. 17

    Why do my WebAPI RESTful routes throw 404 errors?

  18. 18

    Windows- how do I create my own file extensions, and associate them with my own program?

  19. 19

    Why does my DNS MX query return an SOA record?

  20. 20

    Why does my db query return zero(no data) in the required coloumns

  21. 21

    Why does CodeIgniter return my SQL query as an array, with an object inside?

  22. 22

    Why does my Firebase query return the wrong order?

  23. 23

    Why does my mysql query always return an empty result?

  24. 24

    Why using two variable causes my query to return with no row

  25. 25

    Why wont TO_DATE return the TIME section of my query?

  26. 26

    Why does my LINQ query always return 0?

  27. 27

    Why does my SQL query return no rows, when sum is 0

  28. 28

    Lumen GET Requests Return 404 Error

  29. 29

    Why do my WinForm controls flicker before the paint event?

HotTag

Archive