简体   繁体   English

如何在IIS 6.0中将pdf请求重定向到aspx

[英]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. 嗨,我是想知道如何重定向http://mysite.com/pdf/blah.pdfhttp://mysite.com/pages/page.aspx所有PDF文件的请求在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. 您可以为IIS6.0编写一个简单的ISAPI插件。 I had a similar problem of redirecting all HTML to ASP files. 我有一个将所有HTML重定向到ASP文件的类似问题。 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. 如果您只想在不进行任何编程的情况下重定向请求,则IIS6上最简单的选项是使用URL重写。 In this scenario you either direct the browser to do a 301 or 302 redirect to your ASPX page. 在这种情况下,您可以直接引导浏览器执行301或302重定向到您的ASPX页面。 Here are some options that work on IIS6: 以下是在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. 如果要以编程方式执行任何操作,则需要在IIS中为.pdf扩展名创建扩展名映射,以将请求发送到ASP.NET,然后创建HTTP处理程序并将其注册到web.config中以处理对*的请求.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? 如果您是说PDF在磁盘上不存在,并且您想调用aspx页面来查找PDF并将其分发给浏览器?

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. 1)在ISS中的/ pdf /文件夹中设置404重定向,以指向/pages/page.aspx。您可能需要添加带有文件ID的querystring参数,该参数可在page.aspx中使用。

2) Create an HttpHandler to handle this. 2)创建一个HttpHandler来处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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