.NET MVC5应用部分路由报错:目标机器主动拒绝127.0.0.1:44311连接
问题描述
部署.NET MVC5应用及数据库后,部分路由无法正常访问。首页、注册和登录功能运行正常,数据库连接无异常,但访问其他路由时出现如下错误:
No connection could be made because the target machine actively refused it 127.0.0.1:44311
完整异常堆栈:
[SocketException (0x274d): No connection could be made because the target machine actively refused it 127.0.0.1:44311] System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult) +6682835 System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) +88 System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) +260 [WebException: Unable to connect to the remote server] System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) +638 System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) +65 [HttpRequestException: An error occurred while sending the request.] [AggregateException: One or more errors occurred.] System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) +4247326 System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) +12576612 System.Threading.Tasks.Task`1.get_Result() +34 CryptopediaWebApp.Controllers.NetworksController.List() in C:\Users\justu\source\repos\CryptopediaWebApp\CryptopediaWebApp\Controllers\NetworksController.cs:59 lambda_method(Closure , ControllerBase , Object[] ) +62 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22 System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +58 System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228 System.Web.Mvc.Async.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +35 System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45 System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28 System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +45 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9850009 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163
疑问:该异常是由防火墙、代理还是其他原因导致?
问题分析与解决方案
这个异常不是防火墙或代理导致,核心原因是你的MVC应用在NetworksController.List()方法中,尝试调用本地127.0.0.1:44311上的服务,但该服务并未启动,或者端口配置不匹配。
具体排查方向:
- 检查目标服务状态:确认
127.0.0.1:44311对应的后台服务(如API、微服务)是否已启动并正常监听该端口。可使用命令netstat -ano | findstr "44311"查看端口占用情况。 - 核对代码中的端口配置:打开
NetworksController.cs第59行,检查HTTP请求的目标地址是否正确。部署环境中可能保留了开发环境的硬编码端口,需替换为生产环境的正确地址或配置项。 - 验证服务依赖关系:首页、登录等功能无需调用该内部服务,因此能正常运行;而报错的路由依赖这个未启动的服务,导致请求失败。需确保所有依赖服务都已部署并启动。
- 检查应用配置文件:查看
web.config或其他配置文件中,关于该内部服务的地址配置是否正确,是否在部署时未更新。
内容的提问来源于stack exchange,提问作者jsbrcad
相关产品推荐
相关产品推荐

