ASP.NET won't compile to debug

我们两清 提交于 2020-05-29 07:04:40

问题


I have two IIS server machines, A and B. They are both serving an identical ASP.NET Web Forms site.

On A, when I experience an error, I get the detailed error page that shows the source code that generated the exception.

On B, when I experience an error, I get the message...

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:

I want server B to also give me the source code and line numbers when I experience an exception. I have ensured that the web page generating the error has the Debug="true" directive, and that the I have the web.config configured for debug (remember, both sites are using identical files).

Error Page from 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

Error Page from 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

My guess is that for some reason, server B isn't compiling as Debug despite the settings that I have in place.

I think there must be something at the machine level preventing it from giving my source, but I feel like I've checked all the obvious locations in IIS and the machine.config file. Where else should I check to make sure B behaves like A?

Selected portion of my web.config file:

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

Web Forms code behind file that generates my sample error:

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 for the above code behind:

<%@ 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>

回答1:


I will suggest to not open the debug mode to view the actually file and line but to open the trace. The trace is give that informations, the debug give more code to been able to debug the code with a debugger, but on server you do not need that, you only need to know the file and the line.

To open the trace on web.config add it on compiler option as:

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

I have here state the RELEASE, you can only keep the trace flag, and open close the debug, from the debug flag.




回答2:


I just had a similar problem, the only difference i could see is that in one server i published the debug version and in the other (the one not showing the error details) i published the release version. When i changed the second one to debug it showed the details again.




回答3:


Mason, I experienced the same problem as you and can confirm that neither page directive nor web.config directive worked for my .asp page either. I do not have an answer for making that work, I assume that it is a Microsoft bug in their code, documentation and/or their error text.

The workaround for me was to add validateRequest="false" to the <% Page ... > line at the top of my .asp page. It all works as expected now. My webapp is for internal use, the problem only occurred under certain specific conditions and the input is already checked. It would have been nice to get to the bottom of this problem though. Sigh.



来源:https://stackoverflow.com/questions/16175224/asp-net-wont-compile-to-debug

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!