3

我有两台 IIS 服务器机器,A 和 B。它们都服务于相同的 ASP.NET Web 窗体站点。

在 A 上,当我遇到错误时,我会看到详细的错误页面,其中显示了生成异常的源代码。

在 B 上,当我遇到错误时,我会收到消息...

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

当我遇到异常时,我希望服务器 B 也给我源代码和行号。我已确保生成错误的网页具有 Debug="true" 指令,并且我已为调试配置了 web.config(请记住,两个站点都使用相同的文件)。

来自 A 的错误页面:

Server Error in '/' Application.
________________________________________
Test error 
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.ApplicationException: Test error

Source Error: 


Line 10:    protected void Page_Load(object sender, EventArgs e)
Line 11:        {
Line 12:        throw new ApplicationException("Test error");
Line 13:        }
Line 14:    }

Source File: d:\CallLogsSite\Admin\GenerateError.aspx.cs    Line: 12 

Stack Trace: 


[ApplicationException: Test error]
   Admin_GenerateError.Page_Load(Object sender, EventArgs e) in d:\CallLogsSite\Admin\GenerateError.aspx.cs:12
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

B的错误页面:

Server Error in '/' Application.
________________________________________
Test error 
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.ApplicationException: Test error

Source Error: 
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario. 

Stack Trace: 


[ApplicationException: Test error]
   Admin_GenerateError.Page_Load(Object sender, EventArgs e) +46
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

我的猜测是,出于某种原因,尽管我已经进行了设置,但服务器 B 并未编译为 Debug。

我认为机器级别一定有什么东西阻止它提供我的源代码,但我觉得我已经检查了 IIS 和 machine.config 文件中所有明显的位置。我还应该在哪里检查以确保 B 的行为类似于 A?

我的 web.config 文件的选定部分:

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
    </system.web>
</configuration>

生成我的示例错误的文件后面的 Web 表单代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_GenerateError : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
        {
        throw new ApplicationException("Test error");
        }
    }

ASPX页面为上面的代码后面:

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/admin.master" AutoEventWireup="true" CodeFile="GenerateError.aspx.cs" Inherits="Admin_GenerateError" Debug="true" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
</asp:Content>
4

2 回答 2

1

我建议不要打开调试模式来查看实际的文件和行,而是打开跟踪。跟踪是提供该信息,调试提供更多代码以便能够使用调试器调试代码,但在服务器上您不需要它,您只需要知道文件和行。

要在 web.config 上打开跟踪,请将其添加到编译器选项中:

<system.codedom>
    <compilers>
        <compiler compilerOptions="/D:RELEASE,TRACE">
        </compiler>
    </compilers>
</system.codedom>

我这里声明了RELEASE,你只能保留trace标志,并从调试标志打开关闭调试。

于 2013-04-23T17:42:21.270 回答
1

我刚刚遇到了类似的问题,我能看到的唯一区别是我在一台服务器上发布了调试版本,而在另一台服务器上(未显示错误详细信息的服务器)我发布了发布版本。当我更改第二个进行调试时,它再次显示了详细信息。

于 2014-08-12T16:08:44.403 回答