我有一个经典的ASP页面,我想使用IHTTPModule将其封装在一些日志中。
我的问题是,如果我的模块在页面执行之前访问任何表单变量,只要第一个Request.Form被访问,我的ASP页面就会返回一个错误'80004005‘。
如果我将我的模块挂接到asp页面处理之后发生的事件中,那么httpApplication.Context.Request.Form集合就是空的。
示例模块:
using System;
using System.Web;
namespace FormPostTest
{
public class MyModule1 : IHttpModule
{
public void Dispose()
{
//clean-up code here.
}
public void Init(HttpApplication context)
{
/*
With this line (begin request) I get
error '80004005'
/index.asp, line 11 as soon as Request.Form is accessed from the ASP page, however the form collection
is populated.
*/
context.BeginRequest += context_GetFormParams;
/*
* The line causes for form collection to be empty
* */
// context.LogRequest += new EventHandler(context_GetFormParams);
}
private void context_GetFormParams(object sender, EventArgs e)
{
HttpApplication httpApplication = (HttpApplication) sender;
Console.WriteLine(httpApplication.Context.Request.Form.Get("MyFormParam"));
}
}}
这是我的经典ASP页面。
<html>
<head></head>
<body>
<form method="post" action="index.asp">
<input name="MyFormParam" value="Hello" />
<input type="submit" />
</form>
</body>
</html>
<%=Request.form("MyFormParam")%>发布于 2015-04-20 20:43:20
显然(我不知道为什么)访问Form会导致ASP.NET“消耗”http请求的正文;它不再是传统的ASP所能访问的。
一种可能的解决方法是使用Server.TransferRequest,特别是使用preserveForm true。这会导致服务器端传输;客户端不会注意到。
由于这样做会导致服务器将传输的请求当作新的请求来处理,而且假设您希望传输到相同的路径,因此您的IHttpModule也将对第二个“虚拟”请求执行。
这意味着您需要添加一个您的模块可以查找的自定义头部,这样它就可以抑制对第二个请求的进一步处理。
https://stackoverflow.com/questions/28441781
复制相似问题