0

(お客様からの)リモートサーバーに接続しようとしてHttpWebRequest.GetResponseいますが、ログインページで常に例外が発生します:

「リモートサーバーがエラーを返しました:(500)内部サーバーエラー。」

応答ストリームで、エラーページにリダイレクトされたことがわかります。

コードはこれまでのところ(HTTPステータス200)古いASP Webサイトで機能していましたが、まもなく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

ここに多くの同様の質問がありますが、私はまだ私を助けるものを見つけていません。

Q:理由を見つけるのに役立つヒントやアイデアはありますか?プログラムで接続できないようになっている可能性はありますか?

また、 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.

リダイレクトを無効にすると、 「オブジェクトが移動しました」というHTTP302が表示されます。

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 に答える