首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IHttpModule损坏经典表单数据

IHttpModule损坏经典表单数据
EN

Stack Overflow用户
提问于 2015-02-11 05:07:08
回答 1查看 192关注 0票数 2

我有一个经典的ASP页面,我想使用IHTTPModule将其封装在一些日志中。

我的问题是,如果我的模块在页面执行之前访问任何表单变量,只要第一个Request.Form被访问,我的ASP页面就会返回一个错误'80004005‘。

如果我将我的模块挂接到asp页面处理之后发生的事件中,那么httpApplication.Context.Request.Form集合就是空的。

示例模块:

代码语言:javascript
复制
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页面。

代码语言:javascript
复制
<html>
<head></head>
<body>
    <form method="post" action="index.asp">
        <input name="MyFormParam" value="Hello" />
        <input type="submit" />
    </form>
</body>
</html>
<%=Request.form("MyFormParam")%>
EN

回答 1

Stack Overflow用户

发布于 2015-04-20 20:43:20

显然(我不知道为什么)访问Form会导致ASP.NET“消耗”http请求的正文;它不再是传统的ASP所能访问的。

一种可能的解决方法是使用Server.TransferRequest,特别是使用preserveForm true。这会导致服务器端传输;客户端不会注意到。

由于这样做会导致服务器将传输的请求当作新的请求来处理,而且假设您希望传输到相同的路径,因此您的IHttpModule也将对第二个“虚拟”请求执行。

这意味着您需要添加一个您的模块可以查找的自定义头部,这样它就可以抑制对第二个请求的进一步处理。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28441781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档