将JSon数据发布到服务器时的StackOverflowException(HTTP/HTTPS)

Com*_*ity 6 c# debugging asp.net-mvc angularjs visual-studio-2013

我有一个MVC网站,在本地运行就好了.当我正在调试应用程序时,当然,它正在HTTP协议下运行,然后一切正常.

我有一个控制器:

[Route("messages/new/form/invoice"), HttpPost]
public ActionResult Invoice(object model)
{
    var result = JsonConvert.DeserializeObject<dynamic>(model.ToString());
    // Further processing goes here...
}
Run Code Online (Sandbox Code Playgroud)

注意:我已经从这个方法中删除了代码,因为它不重要.

此方法通过AngularJS $ http post服务调用.这是通过以下方式完成的:

this.saveInvoice = function () {
    // Post the form.
    $http({
        method: "POST",
        url: "/messages/new/form/invoice",
        data: { model: JSON.stringify(this.invoice) },
        headers: { 'Content-Type': 'application/json' }
    }).success(function (data) {
        $('#content').html(data);
    }).error(function (error) {
        console.log('An error occured while saving the form: ' + error);
    });
}
Run Code Online (Sandbox Code Playgroud)

通过我的视图调用此函数:

<form id="invoiceForm" name="invoiceForm" ng-submit="invoiceForm.$valid && invoiceCtrl.saveInvoice();" novalidate ng-init="invoiceCtrl.Init(@Model.FlowId)">
Run Code Online (Sandbox Code Playgroud)

但是,如前所述,当在我的本地计算机上运行时,代码运行正常.

但是现在,我正在将它部署到一个服务器上,该服务器的网站是在HTTPS协议下运行的,当然这与我本地计算机上的HTTP不同.

当我执行代码并单击按钮在Web服务器上提交表单时,打开一个新窗口,这是"Visual Studio即时调试器",要求我提供Visual Studio实例来调试它,但是Visual Studio没有安装在该服务器上,这意味着我不需要选择调试器.

这个窗口向我展示了3次.取消所有这些调试器问题后,在我的webbrowser中,我确实在控制台中看到以下内容:

An error occured while saving the form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD     HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Service Unavailable</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">    </HEAD>
<BODY><h2>Service Unavailable</h2>
<hr><p>HTTP Error 503. The service is unavailable.</p>
</BODY></HTML>
Run Code Online (Sandbox Code Playgroud)

这确实意味着应用程序池已崩溃.

所以我现在尝试的是以下内容:

  • 将DEBUG构建部署到服务器.
  • 在web.config中将编译调试更改为false.
  • 安装了Visual Studio远程调试器并远程调试了应用程序.

当我远程调试应用程序时,(意味着我正在附加到远程IIS进程)我在post动作的方法的第一行设置断点(参见上面的控制器).但是,这个方法根本没有被击中,而是StackOverflowException一旦我按下按钮提交表单,远程调试就会抛出.

我希望有人可以指出我正确的方向,因为我迷路了,这让我疯了几个小时.

编辑:添加了web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup>
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <connectionStrings>
    <!-- Removed for security reasons. -->
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="owin:AutomaticAppStartup" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="elmah.mvc.disableHandler" value="false" />
    <add key="elmah.mvc.disableHandleErrorFilter" value="true" />
    <add key="elmah.mvc.requiresAuthentication" value="false" />
    <add key="elmah.mvc.IgnoreDefaultRoute" value="false" />
    <add key="elmah.mvc.allowedRoles" value="*" />
    <add key="elmah.mvc.allowedUsers" value="*" />
    <add key="elmah.mvc.route" value="elmah" />

  </appSettings>
  <location inheritInChildApplications="false">
    <system.web>
      <globalization uiCulture="auto" culture="auto" />
      <authentication mode="Forms">
        <forms loginUrl="~/login" timeout="2880" />
      </authentication>
      <pages>
        <namespaces>
          <add namespace="System.Web.Helpers" />
          <add namespace="System.Web.Mvc" />
          <add namespace="System.Web.Mvc.Ajax" />
          <add namespace="System.Web.Mvc.Html" />
          <add namespace="System.Web.Optimization" />
          <add namespace="System.Web.Routing" />
          <add namespace="System.Web.WebPages" />
          <add namespace="DocTrails3.Net.ViewModels" />
        </namespaces>
      </pages>
      <compilation debug="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1" requestPathInvalidCharacters="&lt;,&gt;,%,&amp;,:,\,?" relaxedUrlToFileSystemMapping="true"  maxRequestLength="1048576" />
      <httpModules>
        <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
        <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
      </httpModules>
    </system.web>
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false" />
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="1073741824" />
        </requestFiltering>
      </security>
      <httpProtocol>
        <customHeaders>
          <remove name="X-Powered-By" />
        </customHeaders>
        <redirectHeaders>

          <clear />
        </redirectHeaders>
      </httpProtocol>
      <modules>
        <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
        <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
        <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
      </modules>
    </system.webServer>
  </location>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <!-- Entity Framework Configuration. -->
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <elmah>
    <security allowRemoteAccess="yes" />
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-sql" applicationName="DocTrails" />
  </elmah>
</configuration>    
Run Code Online (Sandbox Code Playgroud)

编辑:添加了一些有关记录的信息

感谢对这篇文章的评论,我在IIS中进行了双重检查,其中保存了日志.

下面的屏幕截图显示了保存日志的位置:

在此输入图像描述

根据SO的另一篇文章,我知道日志也可以在以下位置找到:

C:\Windows\System32\LogFiles\HTTPERR
Run Code Online (Sandbox Code Playgroud)

所以,我已经执行了一个新的请求,并且在服务器上,Just-In-Time Debugger Windows再次打开几次(我猜是5),但是在两个目录中,(截图中定义的那个,以及上面列出的一个)没有创建文件,也没有使用与请求相同的时间戳进行修改,因此我在那里找不到更多信息.

编辑:添加了有关进一步调查的更多信息

经过一番进一步调查后,我发现问题与HTTPS无关,因为在HTTP协议上运行IIS网站会给我带来同样的错误.

但是,Windows事件日志显示以下条目:

Faulting application name: w3wp.exe, version: 8.5.9600.16384, time stamp:     0x52157ba0
Faulting module name: clr.dll, version: 4.0.30319.34014, time stamp:      0x52e0b784
Exception code: 0xc00000fd
Fault offset: 0x00003022
Faulting process id: 0xd00
Faulting application start time: 0x01d0452cb0b43b02
Faulting application path: C:\Windows\SysWOW64\inetsrv\w3wp.exe
Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Report Id: f1876b51-b11f-11e4-8149-005056a1b9d2
Faulting package full name: 
Faulting package-relative application ID: 
Run Code Online (Sandbox Code Playgroud)

亲切的问候,

Com*_*ity 1

经过几个小时的搜索,我找到了解决方案。

由于 IIS 应用程序池配置为运行 64 位应用程序,因此代码在我的本地计算机上运行良好。在服务器上,它被配置为运行 32 位应用程序。

当我在本地将其更改为 32 位后,我确实收到了 StackOverflowException 并且可以开始调试。

原来是一个String对象。我已将其替换为 StringBuilder,现在一切正常。