I have an IIS 7.5 website running .NET 4.0 in Classic pipeline mode.
I have created a simple default image setup where if an image is called but the physical file does not exist the request is redirected to a default image using the following code in the Application_BeginRequest
event:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.PhysicalPath.EndsWith(".jpg") && File.Exists(Request.PhysicalPath) == false)
{
Context.RewritePath("~/images/nophoto.jpg");
}
}
This works fine on my VS2010 dev server but when on a production environment the Application_BeginRequest event is not called for JPG requests and all I get is the standard HTTP Error 404.0 - Not Found error.
I have tried setting the runAllManagedModulesForAllRequests
option in the Web.Config to true but this does not appear to help:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
From my understanding this should cause all requests to go through .NET and therefore trigger the Application_BeginRequest event?
Desired Outcome:
I'd like all requests to go through .NET so that the Application_BeginRequest event is called for JPGs and a default image is returned if no image is found.
That won't happen with Classic mode, you need to switch to Integrated Mode.
This article might provide an insight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With