将 JSon 数据发布到服务器 (HTTP / HTTPS) 时出现 StackOverflowException
StackOverflowException when posting JSon data to server (HTTP / HTTPS)
我有一个 MVC 网站,运行 在本地就可以了。
当我调试应用程序时,当然,它在 HTTP 协议下 运行 那么一切正常。
我有控制器:
[Route("messages/new/form/invoice"), HttpPost]
public ActionResult Invoice(object model)
{
var result = JsonConvert.DeserializeObject<dynamic>(model.ToString());
// Further processing goes here...
}
注意:我在这里删除了此方法的代码,因为它无关紧要。
此方法通过 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);
});
}
这个函数是通过我的视图调用的:
<form id="invoiceForm" name="invoiceForm" ng-submit="invoiceForm.$valid && invoiceCtrl.saveInvoice();" novalidate ng-init="invoiceCtrl.Init(@Model.FlowId)">
但是,如前所述,当 运行 在我的本地计算机上时,代码运行正常。
但是现在,我将它部署到一个服务器上,该网站是 运行 在 HTTPS 协议下,这当然不同于 HTTP 在我的本地机器上。
当我执行代码并单击按钮在网络服务器上提交表单时,一个新的 window 打开,那是 "Visual Studio Just In Time Debugger" 要求我提供 [=90 的实例=] 来调试它,但是 Visual Studio 没有安装在那个服务器上,这意味着我不需要 select 调试器。
这个window给我看了3次。取消所有这些调试器问题后,在我的网络浏览器中,我确实在控制台中看到以下内容:
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>
这确实意味着应用程序池已崩溃。
所以我现在尝试的是:
- 正在将 DEBUG 版本部署到服务器。
- 在 web.config 中将编译调试更改为 false。
- 安装了 Visual Studio 远程调试器并远程调试了应用程序。
当我远程调试应用程序时,(意味着我附加到远程 IIS 进程)我在 post 操作中方法的第一行设置我的断点(见上面我的控制器)。
但是,这个方法根本没有被击中,而是远程调试确实在我按下按钮提交表单后立即抛出 WhosebugException
。
我希望有人能给我指出正确的方向,因为我迷路了,这让我发疯了好几个小时。
编辑:添加了 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="<,>,%,&,:,\,?" 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>
编辑:添加了一些关于日志记录的信息
感谢对此 post 的评论,我已经在保存日志的 IIS 中进行了双重检查。
下面的屏幕截图显示了日志的保存位置:
根据 SO 上的另一个 post,我知道日志也可以在以下位置找到:
C:\Windows\System32\LogFiles\HTTPERR
所以,我执行了一个新请求,在服务器上,即时调试器 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:
亲切的问候,
经过数小时的搜索,我找到了解决方案。
由于 IIS 应用程序池配置为 运行 64 位应用程序,因此代码在我的本地计算机上 运行 正常。在服务器上它被配置为 运行ning 32 位应用程序。
在本地将其更改为 32 位后,我确实收到了 WhosebugException 并可以开始调试。
原来是String对象。我已将其替换为 StringBuilder,现在一切正常。
我有一个 MVC 网站,运行 在本地就可以了。 当我调试应用程序时,当然,它在 HTTP 协议下 运行 那么一切正常。
我有控制器:
[Route("messages/new/form/invoice"), HttpPost]
public ActionResult Invoice(object model)
{
var result = JsonConvert.DeserializeObject<dynamic>(model.ToString());
// Further processing goes here...
}
注意:我在这里删除了此方法的代码,因为它无关紧要。
此方法通过 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);
});
}
这个函数是通过我的视图调用的:
<form id="invoiceForm" name="invoiceForm" ng-submit="invoiceForm.$valid && invoiceCtrl.saveInvoice();" novalidate ng-init="invoiceCtrl.Init(@Model.FlowId)">
但是,如前所述,当 运行 在我的本地计算机上时,代码运行正常。
但是现在,我将它部署到一个服务器上,该网站是 运行 在 HTTPS 协议下,这当然不同于 HTTP 在我的本地机器上。
当我执行代码并单击按钮在网络服务器上提交表单时,一个新的 window 打开,那是 "Visual Studio Just In Time Debugger" 要求我提供 [=90 的实例=] 来调试它,但是 Visual Studio 没有安装在那个服务器上,这意味着我不需要 select 调试器。
这个window给我看了3次。取消所有这些调试器问题后,在我的网络浏览器中,我确实在控制台中看到以下内容:
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>
这确实意味着应用程序池已崩溃。
所以我现在尝试的是:
- 正在将 DEBUG 版本部署到服务器。
- 在 web.config 中将编译调试更改为 false。
- 安装了 Visual Studio 远程调试器并远程调试了应用程序。
当我远程调试应用程序时,(意味着我附加到远程 IIS 进程)我在 post 操作中方法的第一行设置我的断点(见上面我的控制器)。
但是,这个方法根本没有被击中,而是远程调试确实在我按下按钮提交表单后立即抛出 WhosebugException
。
我希望有人能给我指出正确的方向,因为我迷路了,这让我发疯了好几个小时。
编辑:添加了 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="<,>,%,&,:,\,?" 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>
编辑:添加了一些关于日志记录的信息
感谢对此 post 的评论,我已经在保存日志的 IIS 中进行了双重检查。
下面的屏幕截图显示了日志的保存位置:
根据 SO 上的另一个 post,我知道日志也可以在以下位置找到:
C:\Windows\System32\LogFiles\HTTPERR
所以,我执行了一个新请求,在服务器上,即时调试器 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:
亲切的问候,
经过数小时的搜索,我找到了解决方案。
由于 IIS 应用程序池配置为 运行 64 位应用程序,因此代码在我的本地计算机上 运行 正常。在服务器上它被配置为 运行ning 32 位应用程序。
在本地将其更改为 32 位后,我确实收到了 WhosebugException 并可以开始调试。
原来是String对象。我已将其替换为 StringBuilder,现在一切正常。