【发布时间】:2015-04-10 08:04:28
【问题描述】:
我确实有一个 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 协议当然不同。
当我执行代码并单击按钮以在网络服务器上提交表单时,会打开一个新窗口,这就是“Visual Studio 即时调试器”,要求我提供一个 Visual Studio 实例来调试它,但是该服务器上没有安装 Visual Studio,这意味着我不需要选择调试器。
这个窗口显示给我 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 操作中方法的第一行设置断点(请参阅上面的控制器)。
但是,这个方法根本没有被点击,相反,只要我点击按钮提交表单,远程调试就会抛出一个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="<,>,%,&,:,\,?" 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>
编辑:添加了一些关于日志记录的信息
感谢这篇文章中的 cmets,我已经在 IIS 中进行了双重检查,日志保存在其中。
下面的屏幕截图显示了日志的保存位置:
根据SO 上的另一篇帖子,我知道日志也可以在以下位置找到:
C:\Windows\System32\LogFiles\HTTPERR
所以,我执行了一个新请求,在服务器上,即时调试器窗口再次打开了几次(我猜是 5 次),但在两个目录中,(在屏幕截图中定义的那个) ,以及上面列出的那个)没有创建文件,也没有修改与请求相同的时间戳,所以我在那里找不到更多信息。
编辑:添加了更多关于进一步调查的信息
经过进一步调查,我发现问题与 HTTPS 无关,因为在 IIS 中以 HTTP 协议运行网站也会出现同样的错误。
但是,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 进程,看看问题出在哪里?
-
这就是我正在做的事情,但是我确实收到了 StackOverflowException 甚至没有点击该方法。
-
您是否使用任何代码从 http 重定向到 https?尝试在 Application_BeginRequest() 中设置调试器
-
好吧,也许你可以发布你的 web.config
-
使用任何代码是什么意思?我是直接浏览HTTPS协议下的网站。您认为我在哪里使用任何代码进行重定向。我只是在我的 AngularJS 函数中指向一个相对 URL。
标签: c# asp.net-mvc angularjs debugging visual-studio-2013