user369117
user369117

Reputation: 825

Catch all route not catching static files

I"m trying to create a reverse proxy with ASP.Net Web Api 2, using this example: http://kasperholdum.dk/2016/03/reverse-proxy-in-asp-net-web-api/

Two things that are most important there:

  1. Add a DelegatingHandler: config.MessageHandlers.Add(new ProxyHandler());
  2. Add a catch-all route: config.Routes.MapHttpRoute("abe", "{*path}");

It works fine for the basic url (http://localhost:51101/) when I'm debugging, but a reference to a static file is not redirected:

http://localhost:51101/logos/doodles/2016/sigmund-freuds-160th-birthday-4918124856999936-hp.jpg

If I use that url, I get this error:

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.

Things you can try:
Create the content on the Web server.
Review the browser URL.
Check the failed request tracing log and see which module is calling SetStatus. For more information, click here.

Detailed Error Information:
Module     IIS Web Core
Notification       MapRequestHandler
Handler    StaticFile
Error Code     0x80070002
Requested URL      http://localhost:57221/logos/doodles/2016/sigmund-freuds-160th-birthday-4918124856999936-hp.jpg
Physical Path      c:\users\...\documents\visual studio 2015\Projects\AspNetReversePRoxy2\AspNetReversePRoxy2\logos\doodles\2016\sigmund-freuds-160th-birthday-4918124856999936-hp.jpg
Logon Method       Anonymous
Logon User     Anonymous
Request Tracing Directory      C:\Users\...\Documents\IISExpress\TraceLogFiles\ASPNETREVERSEPROXY2

More Information:
This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
View more information »

Question

Did I make a mistake in the url routing? Is there a way I can catch the static files? So the handler can intercept the call?

Upvotes: 2

Views: 989

Answers (1)

DVK
DVK

Reputation: 2792

In order for static files to be handled, you need to add the following to your configuration file:

<configuration>
   <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
   </system.webServer>
</configuration>

Otherwise managed modules will not be run for requests for static files.

Upvotes: 5

Related Questions