1

Prefix: Unfortunately, rewriting these Classic ASP pages into ASP.NET is not an option. This is a complex legacy application that we're maintaining.

I'm having trouble getting an HttpWebRequest to POST to a Classic ASP page within the same web application. The page works quickly and correctly in a browser.

Expected result:

The HttpWebRequest should POST to the page and get the HTML result.

Actual result:

The HttpWebRequest waits for the default 100-second timeout and then fails.

Error message:

System.Net.WebException
  HResult=0x80131509
  Message=The operation has timed out

Things I've tried:

  • Added a CookieContainer, as suggested here
  • Wrapped the HttpWebResponse in a Using block, as suggested here
  • Attempted to inspect the HTTP traffic using Telerik Fiddler (no traffic was recorded for the request)
  • In order to rule out the ASP page itself as the culprit, reduced its content to a bare minimum:

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>Page</title>
      </head>
      <body>
        <p>This is the page.</p>
      </body>
    </html>
    

Here's the code: (It fails on line 32, GetResponse())

---------------------------------------------------
 Generic Handler: SignIn.ashx
---------------------------------------------------

 1    Imports System.Net
 2
 3    Public Class Labels
 4       Implements IHttpHandler
 5
 6       Sub ProcessRequest(Context As HttpContext) Implements IHttpHandler.ProcessRequest
 7         Dim oFormData As NameValueCollection
 8         Dim oResponse As HttpWebResponse
 9         Dim sResponse As String
10         Dim aPostData As Byte()
11         Dim oRequest As HttpWebRequest
12         Dim sUrl As String
13
14         sUrl = "http://domain.local/signin.asp"
15
16         oFormData = HttpUtility.ParseQueryString(String.Empty)
17         oFormData.Add("username", "username")
18         oFormData.Add("password", "password")
19
20         aPostData = Encoding.ASCII.GetBytes(oFormData.ToString)
21
22         oRequest = WebRequest.Create(sUrl)
23         oRequest.AllowAutoRedirect = False
24         oRequest.ContentLength = aPostData.Length
25         oRequest.ContentType = "application/x-www-form-urlencoded"
26         oRequest.Method = WebRequestMethods.Http.Post
27
28         Using oStream = oRequest.GetRequestStream
29           oStream.Write(aPostData, 0, aPostData.Length)
30         End Using
31
32         oResponse = oRequest.GetResponse
33
34         Using oReader As New StreamReader(oResponse.GetResponseStream)
35           sResponse = oReader.ReadToEnd
36         End Using
37       End Sub
38
39       ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
40         Get
41           Return False
42         End Get
43       End Property
44    End Class

How can I debug this and determine what's going on? (Note that static HTML pages load just fine, as well as ASPX and ASHX files. This occurs only with Classic ASP pages.)

InteXX
  • 6,135
  • 6
  • 43
  • 80
  • Try placing the Classic ASP part in its own Application Pool, the problem arises due to threading *(had this problem with `ServerXMLHTTP` from ASP to ASP, doesn't like trying to `xhr` to itself, so you need to separate the context)*. – user692942 Oct 14 '19 at 09:06
  • @Lankymart ~ Hm, that sounded promising for a moment. I assume you're referring to doing so from the ASP module of the website's IIS configuration page, yes? If so, I couldn't get past the problem even with that. – InteXX Oct 14 '19 at 09:54
  • 2
    Yes, you need to create a separate Application instance inside your site where the Classic ASP is and have that assigned to a different Application Pool to the main Web Application, preferably Classic Pipeline (not .Net). – user692942 Oct 14 '19 at 10:38
  • @Lankymart ~ That didn't work either, I'm afraid. I gave it an extra `iisreset` just for good measure. Even if it were to, however, I couldn't use it in production. We're on shared hosting with GoDaddy, and we only get one Application Pool per website over there. The Plesk control panel is the only path to administration, and it doesn't provide a way to add/convert an application. – InteXX Oct 14 '19 at 16:08
  • 1
    Does the asp url work if you post your data payload to it with curl? Something like: curl -v -i -d username=username -d password=password http://domain.local/signin.asp – feihtthief Oct 14 '19 at 22:09
  • 1
    @feihtthief ~ It does, yes. That's a surprise. What do you have in mind? – InteXX Oct 15 '19 at 03:05
  • 3
    @InteXX Your question lacks the handler configuration which is crucial here. We don't know how do you configure this handler in `system.webServer/handlers`. Anyways, first make sure that this handler will never fire for `signin.asp`, otherwise infinite recursion will definitely occur so the timeout takes place. – Kul-Tigin Oct 15 '19 at 23:41
  • @Kul-Tigin ~ I'm not sure I follow you. What would be the syntax for that? But if I were getting infinite recursion, wouldn't I notice it when stepping through the code? – InteXX Oct 16 '19 at 02:17
  • 1
    Don't you have a handler config in the `web.config` file? Show us. – Kul-Tigin Oct 16 '19 at 14:57
  • @Kul-Tigin ~ I don't, no. In fact, I've never used a handler entry in my `Web.config` file. The need just has never come up. – InteXX Oct 16 '19 at 15:33
  • 1
    Then this must be a generic handler in a file with `.ashx` extension, right? – Kul-Tigin Oct 16 '19 at 16:37
  • @Kul-Tigin ~ Yes, that's correct. Pardon me, I would have clarified this earlier if I'd realized that this was what you were looking for. – InteXX Oct 16 '19 at 18:30
  • 2
    Sorry, I couldn't reproduce the problem on my dev computer (Windows 10 + IIS 10). Also had to move the `line 22` to `line 27` because `aPostData` was not initialized yet. – Kul-Tigin Oct 16 '19 at 23:24
  • 1
    @Kul-Tigin ~ `Also had to move...` Right. That was pointed out by an earlier commenter, who has since removed his comment. I left it unedited here in order to preserve the history. Now on second thought, since he's left the conversation, I should edit this code to fix that (FYI I already did in my local version). Anyway... thanks for sticking with it and for giving it a shot. – InteXX Oct 17 '19 at 01:20
  • 1
    @Kul-Tigin ~ Appreciate your commitment/attempts to help on this one. I'm not sure what the problem was, but it went away after the next reboot. Just FYI. – InteXX Nov 06 '19 at 19:16
  • 1
    Well it was very strange anyway. Thanks for the update @InteXX – Kul-Tigin Nov 06 '19 at 20:39
  • @Kul-Tigin ~ YW – InteXX Nov 07 '19 at 06:06

2 Answers2

0

This one was an oddball. But it went away after the next reboot.

InteXX
  • 6,135
  • 6
  • 43
  • 80
0

If you're calling the same Session in the responding page, you're discovering that ASP is single-threaded and will hang if two separate threads are attempted.

Don't call the session in the responding page, and that may clear things up.

InteXX
  • 6,135
  • 6
  • 43
  • 80
Stephen R
  • 3,512
  • 1
  • 28
  • 45