我有一个经典的 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")%>