使用 ashx/axd 制作处理程序与使用我自己在 ASP.NET 中编写的处理程序有什么区别?

发布于 2024-08-02 19:58:36 字数 594 浏览 13 评论 0原文

这可能很简单,但它确实让我感到困惑。当我实现 IHttpHandler 时,我创建一个处理程序,然后像这样在 web.config 中注册它:

IIS6 Portion:
<httpHandlers>
    <add verb="*" path="*.randomextension" type="MyProgramNameSpace.MyHandler" />
</httpHandlers>

IIS7 Portion:
<handlers>
    <add name="mine" verb="*" path="*. randomextension" type ="MyProgramNameSpace.MyHandler" />
</handlers>

它似乎工作得很好,并且可以为其使用不同的处理程序和选项。它让我可以通过直接访问管道来跳过 Page 类等。然而,我经常遇到文档,其中说我需要将有关 ashx 或 axd 的内容与某些内容一起使用。

这到底是怎么回事?这与处理程序创建有何关系?

这可能非常简单,但由于某种原因,我在处理这个 ashx 或 axd 处理程序时完全感到困惑。

This is probably very simple but it's really confusing me. When I implement the IHttpHandler, I create a handler and then register it like so in the web.config:

IIS6 Portion:
<httpHandlers>
    <add verb="*" path="*.randomextension" type="MyProgramNameSpace.MyHandler" />
</httpHandlers>

IIS7 Portion:
<handlers>
    <add name="mine" verb="*" path="*. randomextension" type ="MyProgramNameSpace.MyHandler" />
</handlers>

It seems to work quite well and get to use different handlers and options for it. It let's me skip the Page class and so forth by directly accessing the pipeline. However, every so often I keep running into documentation where it says I need to use something about ashx or axd with something.

What is all this about? How does this have to do w/ handler creations?

This is probably very easy but for some reason I'm completely confused when going about this ashx or axd handler.

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

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

发布评论

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

评论(3

就是爱搞怪 2024-08-09 19:58:36

.asxh 处理程序只是一个预先存在/预定义的通用处理程序映射。与 .aspx 处理程序不同,您不限于从 Page 派生,并且无法获得完整的 ASP.NET 页面处理程序事件管道。通常,您使用 .ashx 文件来处理采用非标准内容作为输入或返回作为输出的非页面请求。

实际上,.ashx 处理程序和自定义 IHttpHandler 的区别并不大。 .ashx 文件预定义了许多配置,但是您必须使用该扩展名。使用完全自定义的 IHttpHandler,您拥有完全的自由,但需要从头开始配置它。

The .asxh handler is simply a pre-existing/pre-defined generic handler mapping. Unlike the .aspx handler, you are not restricted to deriving from Page, and you don't get the full ASP.NET page handler event pipeline. Generally, you use .ashx files to handle non-page requests that take as input or return as output non-standard content.

The different from an .ashx handler and a custom IHttpHandler is not much, really. A lot of configuration is predefined for .ashx files, but, you are bound to that extension. With a full custom IHttpHandler, you have complete and total freedom, but need to configure it from the ground up.

我是有多爱你 2024-08-09 19:58:36

确实没有什么区别。 .ashx 文件实现 IHttpHandler 就像您所做的那样。只有 .ashx 是预先注册的处理程序,因此您无需自己将其添加到 web.config 中,它已经为您完成了。

There really isn't a difference. .ashx files implement IHttpHandler just like you are doing. Only .ashx is a pre-registered handler so you don't need to add it to the web.config yourself it's already done for you.

自控 2024-08-09 19:58:36

如果您决定按文件类型使用扩展名,则您的处理程序是合适的。

另一方面,如果您尝试返回数据而不使用特定扩展名,则 ashx/ahd 扩展名也同样好。

例如,如果您在数据库中存储了一组图像,则可以注册一个 .JPG 处理程序,该处理程序将从数据库而不是硬盘驱动器中提取图像。您还可以创建一个可以返回任何图像类型的ASHX。

注册扩展可以使 url 对于最终用户来说看起来更“正常”,而 ashx 看起来更通用(甚至极客)。

If you are deciding to use the extension by file type your handler is appropriate.

If on the other hand, you are trying to return data, without a particular extension, the ashx/ahd extension is just as good.

For example, if you have a collection of images stored in a database, you could register a .JPG handler, that would pull the image from the database instead of the hard drive. You could also create an ASHX that could return any image type.

Registering an extension could make the url look more "normal" to the end user, while an ashx looks more generic (even geeky).

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