c# - 请求在 Helper 方法上被中止 : The connection was closed unexpectedly.

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

尝试读取帮助器方法时,我收到“请求已中止:连接意外关闭”错误。

下面是 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 站点并重做 - 删除项目解决方案并从源代码管理中获取新副本

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

最佳答案

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

关于c# - 请求在 Helper 方法上被中止 : The connection was closed unexpectedly.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58138238/

相关文章:

c# - 具有引用成员的结构 : heap or stack?

asp.net-mvc-3 - MVC3 HtmlHelper 返回 '

asp.net-mvc - 找不到内容时,ASP.NET MVC 重定向到默认页面/路由

javascript - 根据 mvc 中的模型属性禁用启用下拉列表

asp.net-mvc - MVC 5 Html helper CheckBoxFor无法在Razor部分中选择

c# - 如何扩展 Html.Raw 以在显示前清理危险的 HTML 数据

c# - 无法为 netstandard1.x 项目安装 Netstandard1.x Nuget 包

c# - 如何将 Spec-flow 表数据转换为不同的值

c# - 使用ajax的跨服务器web服务

c# - ASP.NET MVC - 加载 Maxmind dat 文件