是否可以将以 .aspx 结尾的链接重定向到 .ashx?

发布于 2024-10-12 11:25:35 字数 339 浏览 9 评论 0原文

我们最近发布了一个主要基于 SharePoint 的网站。有些站点只需要返回直接的 XML。该项目的顾问将 xml 返回为 .aspx 页面,并在 page_load 方法中写入响应对象。

经过短暂的研究后,我意识到这可能是错误的方法,因为它调用了我们不需要的 ASPX 页面的所有额外事件。

这是我的问题,我想将这些函数重新创建为 .ashx 与 httphandler 的链接。但是,我希望能够保留以 .aspx 结尾的原始链接以及伴随它们的 get 参数,以决定返回哪种类型的 XML。

可以将 .aspx 结尾链接重写/重定向到 .ashx 链接。或者这会导致 IIS 服务器错误地解释每个 .aspx 吗?

We have a website that we recently released based mostly on SharePoint. Some of the site needed to return just straight XML. The consultants on the project implemented the xml returns as .aspx pages that write the response object in the page_load method.

After a short time researching this, I relize that this is probably the wrong way to do this because it calls all the extra events for a ASPX page that we don't need.

Here's my question, I want to recreate these functions as .ashx links with the httphandler. However, I want to be able to retain the orginal links that ended in .aspx and the get parameters that accompany them to decide which type of XML to return.

Is is possible to rewrite/redirect the .aspx ending links to a .ashx link. Or would that cause the IIS server to interpret every .aspx incorrectly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-10-19 11:25:35

我想你可能很幸运......

我们做了类似的事情。我们的电子商务网络应用程序仅接受 JPG、PNG 和 GIF 文件作为产品图像,但我们希望为每个产品动态创建每个图像。

因此,我们重新映射 JPG、PNG 和 GIF 文件以成为处理程序。

但是,我们不希望映射所有 JPG、PNG 和 GIF 文件,因为这对于静态文件来说效率非常低,因此我们只做了某些操作。

以下是具体操作方法。

如果您的所有 ASPX 文件都遵循没有其他文件共享的类似文件规范,请将其添加到 下的 web.config 中。

<add path="filespec*.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>

如果它们不共享文件规范,则必须将它们一一添加到 web.config:

<add path="oldaspx1.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>
<add path="oldaspx2*.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>
<add path="oldaspx3*.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>

为了使其可用,无论您是否在 IIS7 集成管道中运行,您还可以添加类似的 然后,当传入“oldaspx1.aspx”请求时,自定义处理程序将对其进行处理(非常高效,

无需启动页面生命周期)。

如果这解决了您的问题,请将其标记为已接受的答案,并在左侧打勾。

I think you're probably in luck...

We did a similar thing. Our eCommerce web app only accepts JPG, PNG and GIF files as the images for products, but we wanted every image to be dynamically created for every product.

So, we remapped JPG, PNG and GIF files to become a handler.

However, we didn't want ALL JPG, PNG and GIF files to be mapped since it would be hugely inefficient for static files, so we only did certain ones.

Here is how to do it.

If all of your ASPX files follow a similar file-spec that NO other files share, add this to your web.config under <httpHandlers>.

<add path="filespec*.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>

If they don't all share a file-spec, you'll have to add them one-by-one to web.config:

<add path="oldaspx1.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>
<add path="oldaspx2*.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>
<add path="oldaspx3*.aspx" verb="*" type="MyAssembly.MyHandlerName, MyAssembly"/>

To make this usuable whether or not you are running in the IIS7 integrated pipeline, you could also add similar lines to the <handlers> element

Then when a request comes in for 'oldaspx1.aspx', it will get handled (very efficiently, without the page lifecycle being started) by your custom handler.

If this solves your problem, please mark it as the accepted answer with the check mark to the left.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文