问题标签 [httphandler]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
953 浏览

asp.net - Ashx 处理程序不能通过控制

在 ASP.NET 3.5 应用程序中,我创建了一个 ashx 处理程序,如下所示:

在 aspx 页面中,如果我指定:

然后将网页与图像一起加载到浏览器中。另一方面,如果我使用:

在代码隐藏中:

然后 Image2 控件不加载图片,尽管相关的 html 代码看起来很相似。仅显示替代文本。怎么了?

谢谢

0 投票
3 回答
504 浏览

asp.net - 自定义 HttpHandlers 和不同的处理程序类型

我看到的关于创建自定义处理程序的所有文献都涉及将扩展与处理程序相关联,例如,如果我想要 Ajax 请求的处理程序,我可以在 AjaxHandler 类中实现 IHttpHandler 接口。

现在,要拥有 AjaxHandler 的各个实例,例如 DocAjaxHander、PersonAjaxHandler 等。我将如何在不注册每个单独的 *.ajax 页面的情况下派生我的 AjaxHandler 类的基本 AJAX 处理?

0 投票
1 回答
1823 浏览

asp.net - 使用默认命名空间的 HttpHandler

我有一个名为 Handler 的 HttpHandler,我将它编译成一个 DLL 并放入我的 ASP.NET 应用程序的 /bin 文件夹中。然后我有一个 .ashx 文件:

但我得到一个无法创建类型“处理程序”的错误。

但是,如果我将 Handler 包装在一个免费的命名空间中,比如foo,并将 .ashx 更改为

它工作正常。为什么我不能不使用命名空间,呃,默认命名空间?Microsoft 在 msdn 网站上的许多 HttpHandler 示例中省略了命名空间。

0 投票
8 回答
21065 浏览

asp.net - Using a colon (:) in a url with ASP.NET/IIS

I'm implementing a custom controller in ASP.NET MVC and really want to be able to use a colon in the urls, so that I can identify class/column names and their values, like so:

http://example.com/user:chaiguy

...but apparently ASP.NET or IIS doesn't allow colons in urls. I did some digging and apparently it's considered a security issue, but, I'm using MVC and am handling all url paths manually (just treating them as strings), and not relating them to the file system, so I'm pretty sure this doesn't apply.

I also heard some talk about implementing a custom Http handler or something.

Any thoughts or ideas would be much appreciated.


Er.... why? Seriously, why break standards? – Randolpho

...

I suggest, then, that you investigate building a web service. WCF is a nice technology for that, and it hosts well in IIS.

I happen to like urls, and WCF is way too complicated for my purposes. I want it to be url-compatible, like REST, but capable of more than just navigating hierarchies, or doing well laid-out things. The problem I have with /users/chaiguy is that it is interpreting hierarchy where there is none: in my system "user" is a class, it's not a folder. user:chaiguy means the instance of the user class with the value of "chaiguy", and that is a single entity, that has the potential of having child-entities. So for example:

/user:chaiguy/name

...I would like to display the name of that entity. If I did this with your method, it would look like this:

/users/chaiguy/name

The problem is how do you know what's the class and what's the value? It could be interpreted as

/users/chaiguy:name

in my system, and that doesn't make sense. See what I'm getting at? To give a slightly more complicated example, suppose we want to select a child of the user entity out of multiple instances. So a user might have several email addresses. To select one, we might use:

/user:chaiguy/email:me@here.com/

So it is in fact recursive. It's not a file path, it's more like an XPath (or maybe similar to jQuery based on what little I know of it yet). That is, it's more of a dynamically-evaluated query selection than a hardwired file path. It gets evaluated on the server.

Make no mistake, I'm not building a typical web site or even web service here.

0 投票
3 回答
10156 浏览

asp.net - 将特定文件夹映射到 web.config 中的 HttpHandler

是否可以将文件夹中的所有文件扩展名映射到特定的 HttpHandler(假设它们的文件扩展名映射到 IIS 中的 aspnet_isapi.dll)?

我已将 FLV 扩展名映射到 IIS 中的 ASP.NET,并在我的 Web 应用程序中有一个名为Static的文件夹,其中包含以下文件:

  • 静态/索引.htm
  • 静态/MyFile.flv

索引文件是使用JW FLV 媒体播放器播放 FLV 的基本 html 页面。

在 Web.Config 中,在 HttpHanders 部分下,以下工作(FLV 已加载并成功播放):

但这不是(无法加载视频):

我尝试了各种组合,但运气不佳。

理想情况下,我希望静态文件夹中的所有 FLV 都使用 PassthroughFileHandler,而不是必须在 web.config 中单独指定每个文件名。

0 投票
4 回答
4721 浏览

asp.net - 为我的 ASP.NET Http 处理程序指定确切路径

我使用 Http 处理程序即时生成 XML/Google 站点地图,因此我不需要手动维护 XML 文件。

我已将我的 Http 处理程序映射到我的 web.config 中的“sitemap.xml”,如下所示:

它工作得很好。现在,www.mywebsite.com/sitemap.xml 设置我的 Http 处理程序并执行我想要的操作。但是,这个 url 会做同样的事情:www.mywebsite.com/some/folder/sitemap.xml 我真的不想要那个,即我只想将我的处理程序映射到我的应用程序的根目录。

我尝试将我的 web.config 中的处理程序的“路径”更改为“/sitemap.xml”和“~/sitemap.xml”,但都不起作用。

我在这里错过了什么吗?

0 投票
2 回答
2108 浏览

c# - HttpHandler 实例和 HttpApplication 对象 - 后者...?

一本书显示了一个示例,其中(使用 IIS7 时)配置了以下模块,以便它可以被运行在网站上的任何 Web 应用程序(甚至非 asp.net 应用程序)使用。但:

  1. 如果为非 asp.net 应用程序调用此模块,那么如何或为什么仍会创建 HttpApplication 对象,因为非 asp.net 应用程序不在 CLR 的上下文中运行(因此 Asp.Net 运行时也不会)不跑)?

  2. 假设HttpApplication对象也是为非 asp.net 应用程序创建的,那么为什么 Init() 事件处理程序中的代码必须检查HttpApplication对象是否实际存在?为什么它不存在?这不是 HttpApplication实际实例化 Http 模块实例的对象吗?

这是Http处理程序:



0 投票
4 回答
37354 浏览

c# - IIS7 文件映射 - .asax、.ashx、.asap



IIS 使我们还可以配置 Asp.Net 文件映射。因此,除了 aspx 之外,当请求具有以下文件扩展名时,IIS 也会调用 Asp.Net 运行时:

a) .ascx --> .asmx 扩​​展名用于请求用户控制。

  • 由于无法直接访问用户控件,那么任何人如何以及为什么会向用户控件发送请求?

b) .ashx --> 此扩展名用于 HTTP 处理程序。

• 但是为什么要直接请求 .ashx 页面而不是在配置文件中注册此处理程序并在请求具有某些(非 ashx)扩展名的文件时调用它?

• 此外,由于可以注册多个 Http 处理程序,如果它们都使用 ashx 扩展,Asp.Net 将如何知道调用哪个处理程序?

• 请求的ashx 文件包含什么?也许是 Http 处理程序类的定义?

• 我知道当请求非ashx 页面时我们如何注册要调用的Http 处理程序,但是我们如何为ashx 页面注册Http 处理程序?



c) .asax --> 此扩展名用于请求全局应用程序文件

• 我们为什么要直接调用 Global.asax?

• 我假设当对 Global.asax 发出请求时,会创建一个从 HTtpApplication 类派生的对象,但这次没有进行网页处理?



谢谢




问 - 除了 Asp.Net 能够请求 global.asax 进行编译之外,还有什么其他原因让我选择直接请求扩展名为 .asax 的文件?


• ashx 文件不必注册。它们基本上是一个更简单的 aspx,当您不需要整个页面生命周期时。一个常见的用途是从数据库中检索动态图像。

因此,如果我编写一个 Http 处理程序,我应该将它放在一个扩展名为 .ashx 的文件中,并且 Asp.Net 将构建一个 HttpHandler 对象,类似于它从 .aspx 文件构建页面实例的方式?


• 如果黑客确实尝试请求这些文件之一,您希望发生什么?您当然不希望 IIS 将其视为文本文件并将您的应用程序的源代码发送到浏览器。

Asp.Net 可以对 .cs、.csproj、.config、.resx、.licx、.webinfo 文件类型做同样的事情。即,它向 IIS 注册这些文件类型,以便它可以显式阻止用户访问这些文件


• 仅仅因为您不希望浏览器请求资源,并不意味着您不希望asp.net 引擎处理该资源。这些扩展也是 ASP.Net 为网站模型站点挑选文件以编译的方式。

但是为什么 Asp.Net 也不允许直接请求 .cs、.csproj、.config、.resx、.licx、.webinfo 文件呢?



a) 和 c) - 据我所知,这些不用于处理任何外部请求

我的书声称这两者在 IIS 中映射



我感谢您的帮助

编辑:

b) .ashx 扩展名是在配置文件中定义的,它不是 web.config,而是在 machine.config 中

<add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="True" />
http://msdn.microsoft.com/en-us/library/bya7fh0a.aspx

为什么使用 .ashx:不同之处在于处理 .ashx 的 .NET 类读取 .ashx 文件中的 Page 指令以将请求映射到该指令中指定的类。这使您不必为您拥有的每个处理程序在 web.config 中放置一个显式路径,这可能导致 web.config 非常长。

我认为 Http 处理程序类是在 .ashx 文件中定义的,但扩展名为 .ashx 的文件只包含 Page 指令?

因为我不能 100% 确定我是否理解正确:假设我们有十个 Http 处理程序,我们想通过向 IIS7 发出请求来调用。我假设每个 Http 处理程序都会有特定的 .ashx 文件 --> 因此,如果请求 FirstHandler.asxh,那么将调用该文件中指定的处理程序?

另一个编辑:

我必须承认我仍然对 ashx 扩展有点不确定。

我意识到通过使用它,我们可以例如创建“hey.ashx”页面,其中 Page 指令将告诉在对“hey.ashx”发出请求时调用哪个类(Http 处理程序)——因此无需在其中注册 Http 处理程序网络配置。

但是,如果您以这种方式使用 Http 处理程序,那么它们只会在对具有 .ashx 扩展名的文件发出请求时被调用。因此,如果我希望为具有其他扩展名的文件(例如 .sourceC)调用 Http 处理程序,那么我仍然需要在 web.config 中注册 Http 处理程序?!

0 投票
4 回答
49950 浏览

asp.net - 诊断 IIS 7 和 ASP.NET MVC 上的 404 错误

我有一个用 Cassini 开发和测试的 mvc 应用程序。部署到我在 GoDaddy 上的站点,默认页面正常。点击登录,我得到一个 404。

我在那里运行在 IIS 7 下,所以这是出乎意料的。我的路线很简单:

知道可能发生了什么或如何解决此问题?

0 投票
1 回答
965 浏览

c# - 如何找出 iis7 的 404 错误处理程序中缺少哪个请求路径?

我正在尝试在 iis 7 中创建自定义错误处理程序。

web.config httpErrors 部分:

web.config httpHandler 处理错误:

Image404Handler c#代码:

我不知道如何获取导致 404 错误触发的请求的路径。在 IIS 6 中,Visual Studio 2008 使用此路径被添加到查询字符串中的 aspxerrorpath。

我无法进行远程调试,所以我在这里问是否有人知道该怎么做。