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:
CookieContainer
, as suggested hereHttpWebResponse
in a Using
block, as suggested hereIn 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.)
This one was an oddball. But it went away after the next reboot.
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.
User contributions licensed under CC BY-SA 3.0