2015-02-10 20 views
6

Tôi có trang web MVC đang chạy cục bộ tốt. Khi tôi gỡ lỗi ứng dụng, tất nhiên, nó đang chạy dưới giao thức HTTP thì mọi thứ hoạt động tốt.StackOverflowException khi đăng dữ liệu JSon lên máy chủ (HTTP/HTTPS)

tôi có một bộ điều khiển:

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

Lưu ý: Tôi đã gỡ bỏ mã từ phương pháp này ở đây vì nó là irrelivant.

Phương thức này được gọi qua dịch vụ bưu chính $ http của AngularJS. Này được thực hiện theo cách sau:

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); 
    }); 
} 

Chức năng này được gọi là thông qua quan điểm của tôi:

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

Nhưng, như đã nói ở trên, khi chạy trên máy tính cục bộ của tôi, đang làm việc tốt.

Nhưng bây giờ, tôi đang triển khai nó đến một máy chủ mà trang web đang chạy theo giao thức HTTPS , đó là tắt khóa học khác nhau hơn HTTP trên máy tính địa phương của tôi.

Khi tôi thực thi mã và tôi nhấp vào nút để gửi biểu mẫu trên máy chủ web, cửa sổ mới mở và đó là "Trình gỡ lỗi chỉ trong thời gian của Visual Studio" yêu cầu tôi cho một phiên bản Visual Studio gỡ lỗi , nhưng Visual Studio không được cài đặt trên máy chủ đó, có nghĩa là tôi không cần phải chọn một trình gỡ rối.

Cửa sổ này được hiển thị cho tôi 3 lần. Sau khi hủy bỏ tất cả những câu hỏi này debugger, trong webbrowser của tôi tôi thấy sau trong giao diện điều khiển:

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> 

này có nghĩa là các hồ bơi ứng dụng đã bị rơi.

Vì vậy, những gì tôi đã thử ngay bây giờ là như sau:

  • Triển khai một DEBUG xây dựng đến máy chủ.
  • Trong web.config, thay đổi trình biên dịch thành gỡ lỗi thành sai.
  • Cài đặt trình gỡ lỗi từ xa Visual Studio và gỡ lỗi ứng dụng từ xa.

Khi tôi gỡ lỗi ứng dụng từ xa, (nghĩa là tôi đang gắn với quá trình IIS từ xa) Tôi đang đặt điểm ngắt trên dòng đầu tiên của phương thức trong hành động đăng (xem bộ điều khiển của tôi) ở trên). Nhưng, phương pháp này không bị ảnh hưởng gì cả, thay vào đó, việc gỡ lỗi từ xa sẽ ném một số StackOverflowException ngay sau khi tôi nhấn nút để gửi biểu mẫu.

Tôi hy vọng một người nào đó có thể chỉ cho tôi đúng hướng vì tôi bị lạc và điều đó khiến tôi cảm thấy khó chịu trong giờ làm việc.

Chỉnh sửa: Đã thêm web.cấu hình

<?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>  

Chỉnh sửa: Thêm một số thông tin về cách đăng nhập

Nhờ các ý kiến ​​về bài đăng này, tôi đã hai lần kiểm tra trong IIS, nơi các bản ghi đang được lưu.

Ảnh chụp màn hình dưới đây cho thấy nơi các bản ghi đang được lưu:

enter image description here

Theo bài khác ở đây trên SO, tôi biết rằng các bản ghi cũng có thể được tìm thấy trong các vị trí sau:

C:\Windows\System32\LogFiles\HTTPERR 

Vì vậy, tôi đã thực hiện một yêu cầu mới và trên máy chủ, một lần nữa Cửa sổ gỡ lỗi Just-In-Time sẽ mở ra một vài lần (5 tôi đoán), nhưng trong cả hai thư mục, (được xác định trong ảnh chụp màn hình) và cái được liệt kê ở trên) không có tệp nào được tạo, cũng không được sửa đổi với dấu thời gian giống như yêu cầu, vì vậy tôi không thể tìm thấy bất kỳ thông tin nào khác ở đó.

Edit: thêm một số chi tiết thông tin về nghiên cứu thêm

Sau khi một số nghiên cứu thêm, tôi đã phát hiện ra rằng các vấn đề không liên quan đến HTTPS, vì chạy các trang web trong IIS trên giao thức HTTP mang lại cho tôi cùng một lỗi.

Tuy nhiên, Windows Event Log cho tôi thấy các mục sau:

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: 

Kind regards,

+0

bạn không thể đính kèm từ xa vào quá trình xử lý từ xa của mình và xem vấn đề ở đâu? – Nostradamus

+0

Đó là những gì tôi đang làm, nhưng sau đó tôi nhận được StackOverflowException mà không cần nhấn phương pháp. – Complexity

+0

Bạn có sử dụng bất kỳ mã nào để chuyển hướng từ http đến https không? Hãy thử đặt trình gỡ lỗi trong Application_BeginRequest() – cosset

Trả lời

1

Sau hàng giờ đồng hồ tìm kiếm, tôi đã tìm thấy giải pháp.

Mã đang chạy tốt trên máy tính cục bộ của tôi vì hồ bơi ứng dụng IIS được định cấu hình để chạy ứng dụng 64 bit. Trên máy chủ, nó đã được cấu hình để chạy các ứng dụng 32 bit.

Khi tôi đã thay đổi cục bộ thành 32 bit, tôi đã nhận được StackOverflowException và có thể bắt đầu gỡ lỗi.

Hóa ra đó là một đối tượng String. Tôi đã thay thế nó bằng một StringBuilder và mọi thứ hoạt động tốt ngay bây giờ.

Các vấn đề liên quan