2

IHTTPModule を使用していくつかのログにまとめたい従来の ASP ページがあります。

私の問題は、ページが実行される前にモジュールがフォーム変数にアクセスすると、最初の 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")%>
4

1 に答える 1

1

どうやら (理由はわかりません) アクセスするFormと、ASP.NET が http 要求の本文を「消費」します。従来の ASP からはアクセスできなくなりました。

ここで考えられる回避策はServer.TransferRequest、特にpreserveFormtrue を使用することです。これにより、サーバー側の転送が発生します。クライアントは気づきません。

その効果により、サーバーは転送されたリクエストを新しいものとして処理し、おそらく同じパスに転送したいので、IHttpModuleこの2番目の「仮想」リクエストに対しても実行されます。

つまり、モジュールが検索できるカスタム ヘッダーを追加して、2 番目の要求でそれ以上の処理を抑制できるようにする必要があります。

于 2015-04-20T12:43:19.747 に答える