Classic ASP Request.Form not working when using integrated pipeline

此生再无相见时 提交于 2019-12-23 20:08:57

问题


I have a large corp. web site with mixed classic asp and asp.net currently hosted with a Win 2003 server, IIS 6.

I need to modify all the pages output with some html modifications regardless the world they comes from. The asp part it's really old and badly structured, thus I can't act on any kind of "general include" to apply all the changes we need. Lastly some asp pages outputs code from multiple OCX/COM objects... We are already planning a whole rewrite/migration to .net, but unfortunately it's a long term project and I can't go for quickly.

So I was thinking (and testing) to migrate it to Win 2008 R2, IIS 7.5 and take advantage of integrated pipeline mode where I can modify all output using a .net httpmodule. Everything works fine: I can correctly "inject" html code to pages rendered via asp and asp.net, but I'm running into problems when classic asp pages are going to process form data sent via post (x-www-form-urlencoded) modules.

It seems that classic asp it's missing Request.Form object at all when using Integrated pipeline mode, throwing out error '80004005' at every usage; Request.QueryString instead it's working correctly.

I would not switch back to Classic Pipeline mode as I will loose the benefits of modify the pages rendered by classic ASP. The use of a Isapi filter here it's a nightmare and I won't go into that direction.

Does anyone knows any workaround to get Request.Form working for classic asp when Integrated Pipeline mode is active -or- any way to modify final rendered page output coming from classic asp when using classic pipeline so I can modify it with .net code before sending it to browser?

Thank you for any help, Squiffy

EDIT: Unfortunately, we never found a solution to this problem. In the meantime, we completely rebuilt the site from scratch using much modern solution (yay!). Thanks everybody for your help!


回答1:


I think it's because you use Request.Form in the http module. According to my experiments Request.Form works in asp in integrated mode unless you access it from module before the asp code is processed. There is a suggestion to use HttpServerUtility.TransferRequest on IIS forums in this case. You can use

  const string dontTransferKey = "DONT_TRANSFER_MODULE";
    if (HttpContext.Current.Request.Headers[dontTransferKey] != null)
        return;

    ...............all your http module logic. use Request.Form...................

    HttpContext.Current.Request.Headers.Add(dontTransferKey, "true");
    HttpContext.Current.Server.TransferRequest(HttpContext.Current.Request.Url.AbsolutePath, true);

There are several drawbacks of this solution: if you use more then one http module you need to be sure that they are idempotent. And this could be very difficult in case of third-party modules.




回答2:


The actual reason there is an error reading Request.Form in Classic ASP with your integrated mode + module, is that Classic ASP can only handle reading/processing the binary POST data once.

This means the second read throws an error no matter what.

The documentation of the BinaryRead method mentions the behavior:

The BinaryRead method is used to read the raw data sent by the client as part of a POST request. This method is used for low-level access to this data, as opposed to, for example, using the Request.Form collection to view form data sent in a POST request. After you have used BinaryRead, referring to any variable in the Request.Form collection causes an error. Conversely, after you have referred to a variable in the Request.Form collection, using BinaryWrite will cause an error.

I have seen it often in practice.

In this case, the .NET httpmodule may be reading the POST data, which then causes the Classic ASP Request.Form to error, or vice versa.




回答3:


Not sure if you are using Glimpse, but if you are, I just spent a day trying to figure out why all of a sudden my Classic ASP Request.Forms were failing. Long story short: I commented out the following line in glimpse configuration under :

  <add type="Glimpse.Core.Policy.AjaxPolicy, Glimpse.Core" />

Adding that back in to the ignored types solved my issue. I can now access Request.Form/Request("field") in Classic ASP. I am using Integrated mode, by the way.

Hopes this saves somebody the time I spent today...




回答4:


Just putting it out there, have you tried "Request.Item()" as well?



来源:https://stackoverflow.com/questions/17903722/classic-asp-request-form-not-working-when-using-integrated-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!