0

我正在尝试通过连接到远程服务器(来自我们的客户),HttpWebRequest.GetResponse但在登录页面上我总是遇到异常:

“远程服务器返回错误:(500)内部服务器错误。”

在响应流中,我看到我被重定向到错误页面。

到目前为止,代码(HTTP 状态200)与旧的 ASP 网站一起工作,但它们很快就会迁移到 ASP.NET。如果我手动浏览到 URL,则没有错误。

这是(简化的)代码:

Try
    Dim URL As String = "https://Domain.com/Modules/LoginPage.aspx"
    ' the old URL was similar: https://www.Domain.com/login.asp '  
    Dim req As System.Net.HttpWebRequest = CType(System.Net.WebRequest.Create(URL), System.Net.HttpWebRequest)
    req.Headers.Clear()
    req.AllowAutoRedirect = True
    req.Timeout = 1000 * 30
    req.PreAuthenticate = True
    req.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
    req.Accept = "*/*"
    req.CookieContainer = New System.Net.CookieContainer
    ' following will result in an HTTP 500 Error
    Dim response As System.Net.HttpWebResponse = CType(req.GetResponse(), System.Net.HttpWebResponse)
Catch ex As System.Net.WebException
    ' ex.Response.ResponseUri shows the redirected ErrorPage.aspx
End Try

尽管这里有很多类似的问题,但我还没有找到对我有帮助的问题。

问:您有什么提示或想法可以帮助我找到原因吗?他们是否有可能以某种方式阻止我以编程方式连接?

我还使用Fiddler2ieHTTPHeaders 来分析新旧站点之间是否有任何区别,但我必须承认我不确定必须注意什么。标题似乎相似

旧的“工作” ASP 站点:

GET /login.asp HTTP/1.1
Accept: */*
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: www.domain.blah.com
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: ASPSESSIONIDCSSTADCS=CJDLHKLANAELOKNOJOPCLCDG

HTTP/1.1 200 OK
Date: Wed, 20 Jun 2012 07:36:11 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 3744
Content-Type: text/html
Cache-control: private

GET /StyleSheets/IE/FormStyle.css HTTP/1.1
Accept: */*
Referer: https://www.domain.blah.com/login.asp
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: www.domain.blah.com
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: ASPSESSIONIDCSSTADCS=CJDLHKLANAELOKNOJOPCLCDG

HTTP/1.1 200 OK
Content-Length: 1116
Content-Type: text/css
Last-Modified: Thu, 11 Jul 2002 16:05:52 GMT
Accept-Ranges: bytes
ETag: "03060d4f428c21:31d"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:11 GMT

GET /JScripts/common.js HTTP/1.1
Accept: */*
Referer: https://www.domain.blah.com/login.asp
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: www.domain.blah.com
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: ASPSESSIONIDCSSTADCS=CJDLHKLANAELOKNOJOPCLCDG

HTTP/1.1 200 OK
Content-Length: 16068
Content-Type: application/x-javascript
Last-Modified: Mon, 24 Jan 2011 10:37:53 GMT
Accept-Ranges: bytes
ETag: "8d4371c1b2bbcb1:31d"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:11 GMT

新的 ASP.NET 站点 (HTTP 500)

GET /Modules/Authorization/LoginPage.aspx HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: mo.domain.blah.com
Connection: Keep-Alive

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=if3igvajwackerbutp2ad21i; path=/; secure; HttpOnly
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:55 GMT
Content-Length: 19363

GET /JQuery/css/smoothness/jquery-ui-1.8.18.custom.css HTTP/1.1
Accept: */*
Referer: https://mo.domain.blah.com/Modules/Authorization/LoginPage.aspx
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
If-Modified-Since: Wed, 29 Feb 2012 21:52:34 GMT
If-None-Match: "07d65712cf7cc1:0"
Host: mo.domain.blah.com
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=if3igvajwackerbutp2ad21i

HTTP/1.1 304 Not Modified
Last-Modified: Wed, 29 Feb 2012 21:52:34 GMT
Accept-Ranges: bytes
ETag: "07d65712cf7cc1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:55 GMT

GET /App_Themes/domain/Site.css HTTP/1.1
Accept: */*
Referer: https://mo.domain.blah.com/Modules/Authorization/LoginPage.aspx
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
If-Modified-Since: Wed, 30 May 2012 12:03:02 GMT
If-None-Match: "0dfa1295c3ecd1:0"
Host: mo.domain.blah.com
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=if3igvajwackerbutp2ad21i

HTTP/1.1 304 Not Modified
Last-Modified: Wed, 30 May 2012 12:03:02 GMT
Accept-Ranges: bytes
ETag: "0dfa1295c3ecd1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:55 GMT

GET /CommonControls/Common.js HTTP/1.1
Accept: */*
Referer: https://mo.domain.blah.com/Modules/Authorization/LoginPage.aspx
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
If-Modified-Since: Wed, 18 Apr 2012 12:19:12 GMT
If-None-Match: "0a072765d1dcd1:0"
Host: mo.domain.blah.com
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=if3igvajwackerbutp2ad21i

HTTP/1.1 304 Not Modified
Last-Modified: Wed, 18 Apr 2012 12:19:12 GMT
Accept-Ranges: bytes
ETag: "0a072765d1dcd1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:55 GMT

GET /App_Themes/domain/images/Gray-white-gradient-vertical.gif HTTP/1.1
Accept: */*
Referer: https://mo.domain.blah.com/Modules/Authorization/LoginPage.aspx
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
If-Modified-Since: Fri, 27 Jan 2012 13:47:28 GMT
If-None-Match: "0983c35fadccc1:0"
Host: mo.domain.blah.com
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=if3igvajwackerbutp2ad21i

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: text/javascript
Content-Encoding: gzip
Expires: Thu, 20 Jun 2013 07:36:55 GMT
Last-Modified: Wed, 20 Jun 2012 07:36:55 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:55 GMT
Content-Length: 1929

HTTP/1.1 304 Not Modified
Last-Modified: Fri, 27 Jan 2012 13:47:28 GMT
Accept-Ranges: bytes
ETag: "0983c35fadccc1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:55 GMT

GET /App_Themes/domain/images/customername-Logo_148x38.png HTTP/1.1
Accept: */*
Referer: https://mo.domain.blah.com/Modules/Authorization/LoginPage.aspx
Accept-Language: de
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; DWE40; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
If-Modified-Since: Sun, 26 Feb 2012 10:13:52 GMT
If-None-Match: "0b0b2566ff4cc1:0"
Host: mo.domain.blah.com
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=if3igvajwackerbutp2ad21i

HTTP/1.1 304 Not Modified
Last-Modified: Sun, 26 Feb 2012 10:13:52 GMT
Accept-Ranges: bytes
ETag: "0b0b2566ff4cc1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:56 GMT

HTTP/1.1 304 Not Modified
Last-Modified: Fri, 24 Feb 2012 11:19:44 GMT
Accept-Ranges: bytes
ETag: "0887235e6f2cc1:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 07:36:56 GMT

编辑:根据要求,这里是HttpWebRequest Fiddler 监控的标头。奇怪的是 -没有HTTP 500 错误,为什么我还是会得到异常?

CONNECT mo.domain.blah.com:443 HTTP/1.1
Host: mo.domain.blah.com

HTTP/1.1 200 Connection Established
FiddlerGateway: Direct
StartTime: 10:20:32.948
Connection: close

This is a CONNECT tunnel, through which encrypted HTTPS traffic flows.
To view the encrypted sessions inside this tunnel, enable the Tools > Fiddler Options > HTTPS > Decrypt HTTPS traffic option.

A SSLv3-compatible ServerHello handshake was found. Fiddler extracted the parameters below.

No Proxy-Authorization Header is present.
No Authorization Header is present.

This request did not send any cookie data.

如果我禁用重定向,我会得到带有“对象已移动”的HTTP 302

req.AllowAutoRedirect = False

结果:

HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Location: https://mo.domain.blah.com/ErrorPage.aspx?aspxerrorpath=/Modules/Authorization/LoginPage.aspx
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 10:56:25 GMT
Content-Length: 216

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://mo.domain.blah.com/ErrorPage.aspx?aspxerrorpath=/Modules/Authorization/LoginPage.aspx">here</a>.</h2>
</body></html>

在 fiddler 中启用解密 HTTPS 流量选项后,我可以“看到”默认的 ASP.NET 错误页面:

HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 20 Jun 2012 10:49:29 GMT
Content-Length: 3030

<html>
    <head>
        <title>Runtime Error</title>
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>Runtime Error</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
            <br><br>

            <b>Details:</b> To enable the details of this specific error message to be viewable on remote machines, please create a &lt;customErrors&gt; tag within a &quot;web.config&quot; configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its &quot;mode&quot; attribute set to &quot;Off&quot;.<br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

&lt;!-- Web.Config Configuration File --&gt;

&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;customErrors mode=&quot;Off&quot;/&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the &quot;defaultRedirect&quot; attribute of the application&#39;s &lt;customErrors&gt; configuration tag to point to a custom error page URL.<br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

&lt;!-- Web.Config Configuration File --&gt;

&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt;
    &lt;/system.web&gt;
&lt;/configuration&gt;</pre></code>

                  </td>
               </tr>
            </table>

            <br>

    </body>
</html>

非常感谢任何形式的帮助,因为我的想法已经不多了。

4

1 回答 1

1

您的 ASP 脚本中出现运行时错误。修好它就会好的。

设置此项以启用详细的错误消息(根据您的错误页面)

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
于 2012-06-20T11:19:48.253 回答