C# IHttpModule破坏经典ASP表单数据
我有一个经典的ASP页面,我想使用IHTTPModule在一些日志中对其进行总结 我的问题是,如果我的模块在执行页面之前访问了任何表单变量,那么我的ASP页面在访问第一个Request.form时就会返回一个错误“80004005” 如果我将模块挂接到asp页面处理后发生的事件中,则httpApplication.Context.Request.Form集合为空 示例模块:C# IHttpModule破坏经典ASP表单数据,c#,asp-classic,ihttpmodule,C#,Asp Classic,Ihttpmodule,我有一个经典的ASP页面,我想使用IHTTPModule在一些日志中对其进行总结 我的问题是,如果我的模块在执行页面之前访问了任何表单变量,那么我的ASP页面在访问第一个Request.form时就会返回一个错误“80004005” 如果我将模块挂接到asp页面处理后发生的事件中,则httpApplication.Context.Request.Form集合为空 示例模块: using System; using System.Web; namespace FormPostTest { pub
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")%>
显然(我不知道为什么)访问表单
会导致ASP.NET“消费”http请求的主体;经典的ASP已经无法访问它
这里一个可能的解决方法是使用,preserveForm
true。这会导致服务器端传输;客户不会注意到的
由于这会导致服务器像处理新请求一样处理传输的请求,并且您可能希望传输到相同的路径,因此您的IHttpModule
也将针对第二个“虚拟”请求执行
这意味着您需要添加一个自定义标头,以便您的模块可以查找该标头,以便在第二次请求时禁止进一步处理。谢谢!回答得好。你救了我一天