Share via


HttpWebRequest GetResponse blocked or getting timeout

Question

Monday, September 28, 2020 1:45 PM

Where can I make IIS10 allow outbound internet access for its scripts?

I have a generic handler that requests some info from an external site over http using HttpWebRequest. I get a timeout on my website running on Windows Server 2019, IIS 10. With the same code, same .net version, it works on IIS version 7.5.

If I change the URL it uses to a local URL, it also works with IIS10.

Both external site and local site can be reached by the server browser.

(EDIT: Language nuances)

All replies (4)

Tuesday, September 29, 2020 5:19 AM

Hi,

You could please share the error message, and sample snippet of the HttpWebRequest GetResponse? what is the url which is getting blocked and working? you could try to use fiddler to capture the network trace.

check your antivirus and firewall are not blocking the request.

are you using any authentication?


Tuesday, September 29, 2020 8:51 AM

Thank you for your reply.

It seems to be a new security setting in IIS10, that IIS is not allowed to do http requests to the internet zone, but I can't find this setting.

check your antivirus and firewall are not blocking the request.

There is no antivirus installed on this server. I turned off the firewall completely for all zones, and it did not help.

are you using any authentication?

No authentication

you could try to use fiddler to capture the network trace

It's not my server, so I am hesitant to installing fiddler. Would I be able to record http traffic between IIS10 (the client) and an internet web server (also an IIS)?

sample snippet of the HttpWebRequest GetResponse

    private void LogLine(HttpContext context, string sLogLine)
    {
        context.Response.Write("\n"+DateTime.Now.ToString("HH:mm:ss.fff")+" - "+sLogLine);
    }

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        LogLine(context, "Starting now");
        //Uri uri = new Uri("http://localhost/test.xml");
        Uri uri = new Uri("http://lef.no/test.xml");
        WebRequest wr = WebRequest.Create(uri);
        try
        {
            if (wr is HttpWebRequest)
            {
                HttpWebRequest request = (HttpWebRequest)wr;
                request.Method = WebRequestMethods.Http.Get;
                request.Timeout = 10000;
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        LogLine(context, "Success: " + reader.ReadToEnd());
                        reader.Close();
                    }
                    response.Close();
                }
            }
        }
        catch (Exception e)
        {
            LogLine(context, "Exception: " + e.Message);
        }
    }

will produce:

10:31:41.788 - Starting now
10:31:51.805 - Exception: Timeout für Vorgang überschritten

Means "there was a timeout".

Changing the url to "localhost/test.xml", gives this output:

10:38:28.013 - Starting now
10:38:28.017 - Success: <xml>Test</xml>

The lef.no website is in the "Internet" zone.

If I run these tests on my IIS 7.5 Windows 7 dev machine, it all works just fine.


Wednesday, October 14, 2020 8:51 AM

try to access the public api like google.com


Wednesday, October 14, 2020 4:39 PM

It seems to be a new security setting in IIS10, that IIS is not allowed to do http requests to the internet zone, but I can't find this setting.

Don't make any guess before you learn enough about what happened.

Enable System.NET tracing /en-us/dotnet/framework/network-programming/how-to-configure-network-tracing and see what it says for those HTTP requests. Once you know that, the culprit should be revealed.