gpt4 book ai didi

ASP.NET 无法编译调试

转载 作者:行者123 更新时间:2023-12-02 10:02:33 24 4
gpt4 key购买 nike

我有两台 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 并未编译为“调试”。

我认为机器级别上一定有某些东西阻止它提供我的源代码,但我觉得我已经检查了 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>

最佳答案

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

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

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

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

关于ASP.NET 无法编译调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16175224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com