0

I am attempting to host an application on Azure. Everything is going well except for when I attempt to run the program. Part of the code sends a HTTP GET Request to localhost to retrieve data from other files. However, it results in this error page:

Snippet of Error

Server Error in '/' Application.
An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:1443
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:1443

Source Error:


Line 9:  <div id="menu">
Line 10:   <%=
Line 11:   ServerSideWebReader.WebReader.fetch("http://localhost:1443/Ajax/Widgets/Navigation/Navigation.aspx?id=Welcome to <Removed>", new string[0], new string[0]) %>
Line 12: </div>
Line 13: 

Source File: c:\home\site\wwwroot\Default.aspx    Line: 11

Stack Trace:


[SocketException (0x271d): An attempt was made to access a socket in a way forbidden by its access permissions 127.0.0.1:1443]
   System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +194
   System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +591

[WebException: Unable to connect to the remote server]
   System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data) +508
   System.Net.WebClient.UploadValues(String address, String method, NameValueCollection data) +38
   ServerSideWebReader.WebReader.fetch(String url, String[] paramNames, String[] paramValues) in C:\GuerillaDevCo\ServerSideWebReader\WebReader.cs:18
   ASP.default_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\home\site\wwwroot\Default.aspx:11
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +270
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +14
   System.Web.UI.Page.Render(HtmlTextWriter writer) +30
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +67
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +101
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +27
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1342

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4330.0

We have been able to successfully run this program on Windows Server 2012 previously. It is now running on Azure. I've read in the Azure documentation that any requests to localhost must have a listening socket for that port. However, it states that the specified port must be greater than 1024. If I change the port for the HTTP Request to something besides 80 (HTTP) or 433 (HTTPS) so that I can conform with the constraint, will the HTTP Request still be able to receive a standard response?

Additionally, I would like to know how to create a listening socket using C# or some other tool that works with Azure. This project is currently using ASP.NET V4.8.

TL;DR I want to find a way to successfully allow HTTP Requests to localhost in my application on Azure. I have 2 questions/concerns relating to that that I'd like help with.

  1. Confirmation/Information regarding using a port higher than 1042 for HTTP request to local host.
  2. Information on how to create a listening socket whether with C# or some other appraoch.
  • When you say localhost you mean the azure service is calling itself correct? Have you tried replacing localhost with the correct domain name? – Train Mar 05 '22 at 00:38
  • **Don't** make HTTP requests to yourself - argh - no (there's simply _too many_ reasons to list why that's a bad idea, not least how pre-Core editions of ASP.NET are not good at threading: your application will likely deadlock and freeze entirely). Instead just access the shared logic/getters/factories you need/want directly, from within code. If you want to render an `.aspx` page or `.cshtml` view to a `String` then use the _appropriate_ way to do that: https://stackoverflow.com/questions/647833/rendering-an-aspx-page-in-another-one – Dai Mar 05 '22 at 00:45
  • Why are you using Windows Server **2012** in 2022? It's 10 years old and past its support lifecycle. – Dai Mar 05 '22 at 00:47
  • 1
    @Dai, _"Why are you using Windows Server 2012 in 2022?"_ ... did you miss the part where they are trying to port to Azure? – quaabaam Mar 05 '22 at 00:48
  • You cannot reliably use Sockets - or operate any kind of traditional network server - inside Application code running within IIS (including in Azure Web Sites / Azure App Services) because the application's process lifecycle is controlled by IIS - IIS _by design_ will forcibly terminate and recycle your worker process(es) as it pleases - and unless specifically configured it will not preemptively start your application code except in response to an incoming HTTP request (this is why WCF-in-IIS has all that "net.tcp" and ".NET Process Activation" bollocks you need to configure) – Dai Mar 05 '22 at 00:50
  • @quaabaam They didn't say they were "porting" it to Azure (unless that's a pun...): only that they want wanted it to run it on Azure. If it's going to be an Azure-only application then the WS2012 box is being used as a dev-server, in which case it should be as close to the Azure environment as possible, which is WS2016 or later, at the minimum. – Dai Mar 05 '22 at 00:51
  • @quaabaam That doesn't invalidate my question where I asked **why** they were still using WS2012 though. I want to know why they're using 2012 and not 2016, 2019 or 2022 because they might have a good reason (e.g. compat with legacy software integrations) which requires considerations for Azure compatibility - which is directly relevant to their problem at-hand, or for _bad_ reasons (dev/sysadmin laziness...), in which case I'd tell them to _fix that first_ and only come back afterwards, so we can eliminate irrelevant factors to the problem. – Dai Mar 05 '22 at 00:57
  • You have to move that functionality (navigation widget) into a web app or to a Azure function and then do a http `get` on it. – Anand Sowmithiran Mar 05 '22 at 05:09
  • @Train "When you say localhost you mean the azure service is calling itself correct" Not Azure service itself. This code here is sending a HTTP request to localhost: ServerSideWebReader.WebReader.fetch("localhost:1443/Ajax/Widgets/Navigation/… – Shawn Whitaker Mar 07 '22 at 16:32
  • @Dai Thank you for that information. I appreciate your contribution! I will spend today looking for the approach in c# to get that accomplished! Also regarding the Windows Server 2012, this is because the app was previously hosted and it appeared that it was using Windows Server 2012 when it was running. I'm not familiar with this stack and wanted to avoid modifying/updating any of the code to avoid conflicts I didn't know how to resolve. – Shawn Whitaker Mar 07 '22 at 16:35
  • @AnandSowmithiran Thank you for the advice! I will attempt to manually load the aspx pages recommended by Dai and if that doesn't work I will give your recommend approach a shot! – Shawn Whitaker Mar 07 '22 at 16:39
  • Sorry I'm a little confused. Previously your windows server was calling itself on port 1443. Now you've ported an app to azure and want to call 1443. If localhost:1443 is not the app you ported to azure, Where does localhost:1443 exist? Because your call to localhost:1443 is azure app service calling itself. – Train Mar 07 '22 at 17:08
  • Ah I sorry. I must be confusing what you're meaning. I'm not sure if azure app service is calling itself. And originally there was no defined port so it was just sending HTTP request to localhost. And on the windows 2012 server it did work successfully but because of Azure's security constraint I'm not able to here. Did that help clear up the confusion? Right now I'm following Dai's advice and attempting to call the files through code – Shawn Whitaker Mar 07 '22 at 17:26

0 Answers0