I have a classic ASP page that I want to wrap up in some logging using an IHTTPModule.
My problem is that if my module accesses any form vars before the page is executed, my ASP page returns an error '80004005' as soon as the first Request.Form is accessed.
If I hook my module into events that occur after the asp page has processed, then then httpApplication.Context.Request.Form collection is empty.
Sample module:
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"));
}
}
}
Here is my classic ASP page.
<html>
<head></head>
<body>
<form method="post" action="index.asp">
<input name="MyFormParam" value="Hello" />
<input type="submit" />
</form>
</body>
</html>
<%=Request.form("MyFormParam")%>