I seem to come across some kind of bizarre behavior when tracing is enabled in an ASP.NET MVC application:
When tracing is enabled, the HandleError attribute fails.
I reproduced this with an example of an ASP.NET MVC application with vanilla and wondered if anyone had experienced such a thing.
Playback Steps
Step 1
Create a new ASP.NET MVC application
Step 2
Include trace in web.config:
<trace enabled="true" localOnly="false" pageOutput="false" requestLimit="500" traceMode="SortByTime" />
Step 3
At this point, everything is working fine. The start page loads:
http://localhost/MvcApplication2/
and the trace page works:
http:
Step 4
Simulate an exception somewhere where an attribute HandleErrorcan find it (controller action, view).
I throw an exception in the view Home\Index.aspx:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="System.Threading"%>
<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
<h2><%= Html.Encode(ViewData["Message"]) %></h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
<% throw new NotImplementedException(); %>
</p>
</asp:Content>
Result
, HandleError (Shared\Error.aspx), ASPE CustomErrors:
http://localhost/mvcapplication2/GenericErrorPage.htm?aspxerrorpath=/MvcApplication2/
5
web.config:
HandleError (Shared\Error.aspx) :
, .
4, :
HandleErrorHandleError (Shared\Error.aspx) , ASP.NET
, ELMAH, , :
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Web.HttpException: Multiple controls with the same ID 'ctl00' were found. Trace requires that controls have unique IDs.
at System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize, Int32 controlStateSize)
at System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState)
at System.Web.UI.Control.BuildProfileTree(String parentId, Boolean calcViewState)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.views_error_internalerror_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\c3a94d6e\b487cfcc\App_Web_m5awwxof.0.cs:line 0
at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
( , HandleError "InternalError.aspx" "Error.aspx" )
?
, , cookie , - ?
!