ASP.NET不会编译为调试

时间:2013-04-23 17:09:15

标签: asp.net iis

我有两台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>

3 个答案:

答案 0 :(得分:1)

我建议不要打开调试模式来查看实际的文件和行,但要打开跟踪。跟踪给出了这些信息,调试提供了更多的代码,可以用调试器调试代码,但是在服务器上你不需要它,你只需要知道文件和行。

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

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

我在这里陈述RELEASE,你只能保留跟踪标志,并从调试标志打开关闭调试。

答案 1 :(得分:1)

我只是遇到了类似的问题,唯一的区别是我在一台服务器上发布了 debug 版本而在另一台服务器上(没有显示错误详情的那台)我发布了< strong>发布版本。 当我将第二个更改为调试时,它再次显示了详细信息。

答案 2 :(得分:-1)

梅森,我遇到了与您相同的问题,可以确认页面指令和web.config指令均不适用于我的.asp页面。对于该功能,我没有答案,我认为这是他们代码,文档和/或错误文本中的Microsoft错误。

对我来说,解决方法是在 <%Page ...> 行顶部添加 validateRequest =“ false” 。我的.asp页。现在一切都按预期工作。我的webapp供内部使用,该问题仅在某些特定条件下发生,并且已经检查了输入。不过,深入了解此问题本来很好。叹气。