【问题标题】:The request was aborted: The connection was closed unexpectedly. on Helper methods请求被中止:连接意外关闭。关于辅助方法
【发布时间】:2020-01-27 23:57:02
【问题描述】:

我收到请求被中止:尝试读取辅助方法时连接意外关闭错误。

下面是 Index.cshtml 中的代码

@Helper.InsufficientRightsDataBoundScript(!user.HasAccessToBuisnesses, "Insufficient rights to view this page.")

helper.cs

@helper InsufficientRightsDataBoundScript(bool noAccessToRecords, string defaultMessage, string methodSuffix = "")
{
    <script language="javascript">
        @{
            var x = "function OnDataBound"+ (string.IsNullOrEmpty(methodSuffix) ? string.Empty : "_") + methodSuffix+"(e) {";
            @x;
        }

        var grid = e.sender;
        if (grid.dataSource.total() === 0) {

            var filter = grid.dataSource.filter();
            var msg = (filter && filter.filters.length > 0) ? "No rows match the filter criteria." : "@defaultMessage";
            var colCount = grid.columns.length;
            if (@noAccessToRecords.ToString().ToLower() === true)
                msg = "No Businesses Exist.";
            $(e.sender.wrapper)
                .find('tbody')
                .append('<tr class="kendo-data-row"><td colspan="' + colCount + '"><div class="alert alert-danger">' + msg + '</div></td></tr>');
            }
        }

    </script>
}

下面是完整的堆栈跟踪

The request was aborted: The connection was closed unexpectedly. 
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.WebException: The request was aborted: The connection was closed unexpectedly.

Source Error: 


[No relevant source lines]

Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\984a967f\ceba3ee6\App_Code.6rfuon9f.1.cs    Line: 0 

Stack Trace: 


[WebException: The request was aborted: The connection was closed unexpectedly.]
   System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) +6926936
   System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size) +118
   System.IO.BinaryWriter.Write(Int32 value) +73
   Microsoft.WebTools.BrowserLink.Runtime.Tracing.MappingDataWriter.WriteBeginContext(Int32 sourceStartPosition, Int32 sourceLength, Boolean isLiteral, String sourceFilePath, Int32 renderedOutputIndex, Int32 renderedPosition) +81
   Microsoft.WebTools.BrowserLink.Runtime.Tracing.DataDispatchExecutionListener.BeginContext(PageExecutionContext context) +127
   CallSite.Target(Closure , CallSite , Object , Object ) +199
   System.Web.WebPages.Instrumentation.PageExecutionListenerAdapter.BeginContext(PageExecutionContextAdapter context) +184
   System.Web.WebPages.Instrumentation.InstrumentationService.BeginContext(HttpContextBase context, String virtualPath, TextWriter writer, Int32 startPosition, Int32 length, Boolean isLiteral) +160
   System.Web.WebPages.HelperPage.BeginContext(TextWriter writer, String virtualPath, Int32 startPosition, Int32 length, Boolean isLiteral) +105
   ASP.<>c__DisplayClassb.<InsufficientRightsDataBoundScript>b__a(TextWriter __razor_helper_writer) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\984a967f\ceba3ee6\App_Code.6rfuon9f.1.cs:0
   System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
   System.Web.WebPages.WebPageBase.Write(HelperResult result) +80
   ASP._Page_Views_businesses_Index_cshtml.Execute() in d:\Source\OLT\Feature\Nv.Tax.OLT\Views\Businesses\Index.cshtml:86
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
   System.Web.WebPages.StartPage.RunPage() +17
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
   System.Web.WebPages.StartPage.RunPage() +17
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(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.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   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) +36
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   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.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   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) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9849569
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

我目前尝试了以下方法: - 删除 %TEMP% - 删除 C:\Windows\Temp - 清洁构建 - 删除 IIS 站点并重做 - 删除项目解决方案并从源代码管理中获取新副本

我以前从未见过这样的事情,所以我现在有点迷茫。任何帮助或建议将不胜感激。

【问题讨论】:

  • 我也有同样的问题。你找到解决办法了吗?
  • 我想我解决了这个问题,但这个解决方案根本没有意义。基本上我从 2019 年切换到 Visual Studio 2017,问题就消失了。
  • 我有同样的问题,似乎是因为浏览器链接developercommunity.visualstudio.com/content/problem/809919/…我禁用了浏览器链接作为解决方法
  • @vfabre 对我来说也一样。我想您应该创建一个特定的答案,以便将来参考。

标签: c# asp.net-mvc html-helper system.net.webexception


【解决方案1】:

根据this,问题出在浏览器链接上。我在使用 Visual Studio 2019 的 ASPNET MVC 5 项目中遇到了同样的问题。关闭浏览器链接后一切正常。

【讨论】:

  • 这对我来说仍然是最新版本的 Visual Studio 的问题。这是一个 VS 错误还是由我们项目中的某些东西引起的?我必须为 MVC5 项目永久禁用 BrowserLink 似乎很奇怪。
  • 是的,直到今天仍然如此。而且是的,关闭浏览器链接仍然是解决方案。我希望我能在几个小时前找到它……老实说,浏览器链接一直都是垃圾,所以我不知道我为什么要启用它。
猜你喜欢
  • 1970-01-01
  • 2021-12-28
  • 1970-01-01
  • 2020-11-05
  • 2010-09-22
  • 1970-01-01
  • 1970-01-01
  • 2012-04-26
相关资源
最近更新 更多