2

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")%>
Dave
  • 1,068
  • 12
  • 26

1 Answers1

1

Apparently (I don't know why) accessing Form causes ASP.NET to "consume" the http request's body; and it's no longer accessible to classic ASP.

A possible workaround here is to use Server.TransferRequest, and specifically with preserveForm true. This causes a server-side transfer; the client won't notice.

Since that effective causes the server to process the transferred request as if it were new, and since presumably you want to transfer to the same path, your IHttpModule will also execute for this second "virtual" request.

That means you need to add a custom header that your module can look for so it can suppress further handling on the second request.

Eamon Nerbonne
  • 47,023
  • 20
  • 101
  • 166