如何在 Azure 应用服务上处理对 LocalHost 的 HTTP Get 请求
我正在尝试在 Azure 上托管应用程序。除了当我尝试运行该程序时,一切都很顺利。部分代码向本地主机发送 HTTP GET 请求以从其他文件检索数据。但是,它会导致以下错误页面:
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
我们之前已经能够在 Windows Server 2012 上成功运行此程序。它现在正在 Azure 上运行。我已阅读 Azure 文档 对本地主机的任何请求都必须有该端口的侦听套接字。但是,它规定指定的端口必须大于 1024。如果我将 HTTP 请求的端口更改为 80 (HTTP) 或 433 (HTTPS) 以外的端口以便我可以符合约束,则 HTTP 请求仍然是能够收到标准回复吗?
此外,我想知道如何使用 C# 或其他与 Azure 配合使用的工具创建侦听套接字。该项目当前使用 ASP.NET V4.8。
长话短说 我想找到一种方法来成功允许在 Azure 上的应用程序中向本地主机发送 HTTP 请求。我有 2 个与此相关的问题/疑虑需要帮助。
- 有关使用高于 1042 的端口向本地主机发出 HTTP 请求的确认/信息。
- 有关如何使用 C# 或其他方法创建侦听套接字的信息。
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:
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.
- Confirmation/Information regarding using a port higher than 1042 for HTTP request to local host.
- Information on how to create a listening socket whether with C# or some other appraoch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论