简体   繁体   中英

how to redirect a pdf request to aspx in iis 6.0

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.

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.

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM