c# - 这个错误是什么意思?远程主机关闭了连接。错误代码为 0x80070057

标签 c# asp.net-mvc-2 iis-7

尽管有几个人问过这个问题,但似乎问题与我的不同。就像他们中的大多数人似乎得到了行号,或者问题可能是由 ViewState 引起的。

我使用的是 Asp.net 4.0 MVC 2.0,所以我认为我根本没有使用 ViewState。我的错误不给我行号也很好。所以我不知道是什么原因造成的,也不知道我的代码在哪里。

System.Web.HttpException (0x80070057): The remote host closed the connection. The error code is 0x80070057.
   at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
   at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
   at System.Web.HttpResponse.Flush(Boolean finalFlush)
   at System.Web.HttpResponse.Flush()
   at System.Web.HttpResponse.End()
   at System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)
   at System.Web.HttpResponseWrapper.Redirect(String url)
   at MySolutionFile.Domain.RequiresSSL.OnActionExecuting(ActionExecutingContext filterContext)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

有人知道为什么吗?

最佳答案

我们将“Response.Redirect”与“return View()”混在一起导致了这个问题。浏览器已重定向,但我们仍试图返回 View ...

错误代码

    switch (userType)
    {
        case "None":
            Response.Redirect("http://" + host + "/");
            break;
        default:
            Response.Redirect(internalwebhost + "/exit/");
            break;
    }

    return View();

更好的代码

    switch (userType)
    {
        case "None":
            url = "http://" + host + "/";
            break;
        default:
            url = internalwebhost + "/exit/";
            break;
    }

    return new RedirectResult(url);

关于c# - 这个错误是什么意思?远程主机关闭了连接。错误代码为 0x80070057,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3790022/

相关文章:

iis-7 - IIS7应用预热模块正式发布?

ASP.net 客户端 ID 模式

php - Windows/Temp 目录中充满了阻塞服务器的 Php Session 文件

c# - 删除 PayPal 中的送货地址信息

c# - 如何在 Asp.Net mvc 5 的 grid.mvc 中添加两个按钮

asp.net-mvc-2 - 在 MonoDevelop 中使用 XSP4

validation - 关于构建 asp.net mvc 应用程序的建议

c# - 通用方法 : Cannot convert from Tuple to T

c# - 无法使用 C# 将数据插入 SQL 数据库

asp.net-mvc - 更正缺少 ASP.Net MVC Controller 的 404 消息