You need to make IIS forward PDF requests to ASP.NET for your stuff to take place.
Example Article:
Quoting relevant part from article:
Hooking PDF Files Into the Web
Application with IIS
It was easy testing the custom HTTP
handler in Visual Studio's built-in
web server, Cassini, since all
document types are automatically
processed in the web application by
default. However, IIS needs a few
tweaks. IIS will ignore sending
requests for static documents, such as
PDF files, to the ASP .NET web
application and will instead simply
serve the request. We need to
intercept the request and allow our
web application to process it first.
To do this, we'll need to setup an IIS
mapping for PDF files (*.pdf), telling
IIS to send the request to our web
application.
In IIS 5/6
- Open the Internet Information Services (IIS) Manager.
- For your web application, on the Directory tab, click the Configuration
button.
- On the Mappings tab of the Application Configuration window,
click the Add button to add a new
Application Extension Mapping.
In the Executable field, enter: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
In the Extension field, enter: *.pdf
- Select All Verbs and checkmark Script Engine and Check that file
exists.
In IIS 7
- Open the Internet Information Services (IIS) Manager.
- Open the Handler Mappings setting.
- Add a Managed Handler.
- For Request Path enter: *.pdf
- For Type, select the custom HTTP handler for the application.
A shortcut to this in IIS 7, as
mentioned above in the article, is to
define the mapping in the web.config
within the system.webServer handlers
section, as follows:
<system.webServer>
...
<handlers>
<add name="PDF" path="*.pdf" verb="*" type="CustomFileHandlerDemo.Handlers.FileProtectionHandler" resourceType="Unspecified" />
...
</handlers>
</system.webServer>
The above code in the web
application's web.config will
automatically add the entry into the
IIS 7 Handler Mappings section.
The above steps may differ depending
on your version of IIS, but should be
similar for adding a document mapping
to the web application. Once
configured, requests for PDF documents
will be sent to the web application,
where you can process the request
before allowing access.
Remember, in Visual Studio's built-in
web server, module mappings are not
required, as all requests for files go
through the web application, making it
easy to test the custom http handler.
Because you don't use custom handler, you just need to set the handler to ASP.NET default handler. This is the same handler set to ".aspx" already in IIS.