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")%>