views:

363

answers:

3

Hi i'm wondering how to redirect a http://mysite.com/pdf/blah.pdf to http://mysite.com/pages/page.aspx for all pdf file requests in iis 6.0/asp.net. Haven't been able to find anything definitive by searching.

+1  A: 

You can write a simple ISAPI plugin for IIS6.0. I had a similar problem of redirecting all HTML to ASP files. I wrote a blog post about the plugin. Check it out and see if it helps.

Shoban
yeah with iis6.0 you write or buy a plugin to accomplish this. thanks.
A: 

If you mean the PDF doesnt exist on disk and you want to call the aspx page to look for and server out the PDF to the browser?

If so there are 2 ways:

1) setup a 404 redirect in ISS on the /pdf/ folder to point to /pages/page.aspx YOu may need to add a querystring parameter with the ID of the file, which will be avilable in the page.aspx.

2) Create an HttpHandler to handle this.

Mark Redman
+1  A: 

If you just want to redirect the request without anything programmatic the easiest option on IIS6 is using URL rewriting. In this scenario you either direct the browser to do a 301 or 302 redirect to your ASPX page. Here are some options that work on IIS6:

If you want to do anything programmatically you'll need to create an extension mapping in IIS for the .pdf extension to get the request into ASP.NET, and then create an HTTP handler and register it in web.config to handle requests to *.pdf.

<httpHandlers>
    <add verb="*" path="*.pdf" type="MyNamespace.MyPdfHandler, MyAssembly"/>
</httpHandlers>
John Clayton