问题标签 [httpmodule]

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 投票
2 回答
3464 浏览

c# - 未显示 HttpModule、Response.Filter 和图像

HttpModule 工作正常(“hello”被替换为“hello world”),但由于某些原因,当模块添加到 Web.config 时,WebForms 上的图像不显示。从 Web.config 中删除模块后,将显示 WebForms 上的图像。

有谁知道为什么?

使用或不使用 HttpModule 生成的 HTML 完全相同!

//过滤器 - 将“hello”替换为“hello world”

0 投票
3 回答
6601 浏览

asp.net - HttpModule for Error Handling and Missing Images

I have an HttpModule that I have put together from cobbling a couple of different sources online together into something that (mostly) works with both traditional ASP.NET applications, as well as ASP.NET MVC applications. The largest part of this comes from the kigg project on CodePlex. My problem is in dealing with 404 errors due to a missing image. In the following code, I have had to explicitly look for an image being requested through the AcceptedTypes collection in the HttpContext's Request object. If I don't put in this check, even a missing image is causing a redirect to the 404 page defined in my section in the Web.config.

The problem with this approach is that (beyond the fact it smells) is that this is just for images. I would basically have to do this with every single content type imaginable that I do not want this redirect behavior to happen on.

Looking at the code below, can someone recommend some sort of refactoring that could allow for it to be more lenient with non-page requests? I would still want them in the IIS logs (so I would probably have to remove the ClearError() call), but I do not think that a broken image should impact the user experience to the point of redirecting them to the error page.

The code follows:

Any feedback would be appreciated. The app that I am currently doing this with is an ASP.NET MVC application, but like I mentioned it is written to work with an MVC handler, but only when the CurrentHandler is of that type.

Edit: I forgot to mention the "hack" in this case would be the following lines in OnError():

0 投票
1 回答
876 浏览

asp.net - 文件上传进度如何报告?

我一直在尝试实现 ajax 样式的文件上传。我想知道我们必须做什么来报告上传进度。我正在尝试在我的 asp.net 网页中实现这一点。

我了解我们可以在网页上上传 ajax 样式的文件的机制。我一直在谷歌上搜索如何显示进度条,但我没有看到正确的解释。但我开始明白我们必须从服务器端以某种方式管理它。(cf文件上传进度

任何想法/代码将不胜感激。提前谢谢。

0 投票
2 回答
680 浏览

model-view-controller - 使用 mvc/routing 模块时,每个请求都会调用 Http 模块

我正在开发一个 http 模块,它通过 Authenticate 事件连接到 FormsAuthentication 模块。

在调试时,我注意到模块(和所有其他注册的模块)在每次客户端请求资源时都会被命中(也当它请求图像、样式表、javascript 文件(等)时)。这在以集成管道模式在 IIS 7 服务器上运行以及通过 webdev 服务器进行调试(在非集成管道模式下)时都会发生

由于我正在开发一个包含大量图像的网站,这些图像通常不会被客户端浏览器缓存,它会在很多不必要的时间里碰到模块。

我正在使用 MVC 及其路由机制(System.Web.Routing.UrlRoutingModule)。创建新网站时,IIS 7 (system.webServer) 部分的 runAllManagedModulesForAllRequests 属性在 web.config 中默认设置为 true,顾名思义,它会为每个请求调用所有模块。

如果我将 runAllManagedModulesForAllRequests 属性设置为 false,则不会调用任何模块。

似乎这是因为路由模块或 mvc(不知道确切原因),这导致 asp.net(aspx)处理程序永远不会被调用,因此事件和模块永远不会被调用(仅一次就像假设的那样)。

我通过尝试调用“mydomain.com/Default.aspx”而不只是“mydomain.com/”来测试这一点,并且正确地它只像预期的那样调用模块一次。

我该如何解决这个问题,以便它只在请求页面时调用模块一次,而不是在请求所有其他资源时调用模块?

有什么方法可以注册所有请求都应该触发 asp.net (aspx) 处理程序,但对特定文件类型扩展名的请求除外?当然,如果我选择使用像 /content/images/myimage123 这样的 URL 来获取图像(没有扩展名),那当然不会解决问题。但我想不出任何其他方法来解决它。

有没有更好的方法来解决这个问题?

我试图设置这样的 ignoreRoute routes.IgnoreRoute("content/{*pathInfo}"); 其中 content 文件夹包含 seperat 子文件夹中的所有图像、javascript 和样式表,但它似乎没有改变任何东西。

在设置处理程序时,我可以看到许多不同的可能性,但我似乎无法弄清楚应该如何设置一个可以使用路由模块并具有 /blog/post123 之类的网址而不调用请求图像、javascript 和样式表(等)时的模块。

希望有人可以帮助我吗?

马丁

0 投票
4 回答
4368 浏览

asp.net - ASP.NET 响应过滤器重新格式化 ASPX 页面的呈现输出?

我创建了一个简单的 HttpModule 和响应流来重新格式化网页的呈现输出(参见下面的代码片段)。

在 HttpModule 中,我将 Response.Filter 设置为我的 PageStream:

在 PageStream 中,我覆盖了 Write 方法,以便重新格式化呈现的输出:

在简单的 HTML 页面 (.html) 上使用它时效果很好,但是当我在 ASPX 页面 (.aspx) 上使用此方法时,Write 方法会被调用多次,将重新格式化分成不同的步骤,并可能破坏字符串替换操作。

我该如何解决这个问题?有没有办法让 ASPX 页面不调用 Write 多次,例如通过更改其缓冲区大小,或者我完全选择了错误的方法,通过使用此 Response.Filter 方法来操作呈现的输出?

0 投票
1 回答
1693 浏览

asp.net - HttpContext.Current.Session 在我无权访问的模块中为空

我正在尝试按照此处某人的建议使用此上传控件:

http://darrenjohnstone.net/2008/07/15/aspnet-file-upload-module-version-2-beta-1/

所以我正在尝试实现一个自定义处理器,以便将上传的文件存储在会话中。但是,当文件被传递给处理器(从 HttpModule)时,SEssion 为空。

谷歌搜索显示我应该在模块中添加“IREquiresSessionState”或其他内容,但是我无法访问模块,因为它位于 dll 中 - 所以我需要一个替代方案。谁能想到一个?

谢谢

0 投票
1 回答
720 浏览

asp.net-mvc-routing - ASP.NET MVC 2 和自定义 httpModule 优先级

我在现有的 Web 应用程序项目中有一个自定义 HttpModule 重写引擎,它映射表单的 url

/汤姆/迪克/哈利/.../.../...

到存储在数据库中的分层导航系统,最终导致对请求路径解析到的 .aspx 页面的 HttpContext.Current.RewritePath() 调用。

我有兴趣将 MVC 与现有应用程序混合。如果 MVC 代码运行良好并且比模型背后的代码提供了真正的好处,我将如何处理我的重写引擎和路由表之间的优先级?在 HttpModule 之前引用路由表,之后?两个都叫吗?

0 投票
1 回答
162 浏览

c# - DLL依赖和HTTP模块

我在 dll 中有一个 HTTP 模块,在 Web 应用程序中使用。我需要在 Web 应用程序中调用一个类(使用在 dll 中定义的接口 - 所以我们没有紧密耦合)。

我在 web.config 的 appsettings 中定义了类,但不知道如何创建实例。我使用Type.GetType,但它只返回一个空值。

我的 app.config 是

我的 Type.GetType 调用是

任何帮助将不胜感激。

谢谢

波奇

0 投票
4 回答
9692 浏览

asp.net - 将 IoC 依赖注入自定义 HTTP 模块 - 如何?(ASP.NET)

我有一个自定义 HTTP 模块。我想使用我的 IoC 框架注入记录器,这样我就可以在模块中记录错误。但是,我当然没有构造函数,所以不能将它注入其中。解决这个问题的最佳方法是什么?

如果您需要特定的 IoC 容器 - 我目前正在使用 Windsor,但可能很快会转向 AutoFac。

谢谢

0 投票
6 回答
18562 浏览

.net - 如何使用 HttpModule 记录请求输入流,然后重置 InputStream 位置

我正在尝试使用 IHttpModule 记录 http 请求的内容,如下所示:

问题是在将输入流读到最后之后,InputStream 似乎要么消失了,要么更有可能是光标在流的末尾。

我已经尝试过request.InputStream.Position = 0;request.InputStream.Seek(0, SeekOrigin.Begin);但都没有工作。