Solved

Application_Error in Global.asax not firing

Posted on 2009-07-13
11
3,237 Views
Last Modified: 2013-11-08
The Application_Error fires in development, but not on production server. I have stripped out everything I can think of to eliminate other possible errors. With the code below in development I get a page with "Found ERROR" on it. In production I get the default ASP.NET error page with the stack trace. I have been searching for an answer for a while, any help will be appreciated.
Index.aspx.cs:

        protected void Page_Load(object sender, EventArgs e)

        {

            throw new Exception("ERROR");

        }

 

Global.asax.cs:

        protected void Application_Error(object sender, EventArgs e)

        {

            Response.Write("Found ERROR");

            Server.ClearError();

        }

Open in new window

0
Comment
Question by:hwsitservices
  • 6
  • 4
11 Comments
 
LVL 15

Expert Comment

by:jinal
ID: 24846266
Please check web.config on production server.
1. What is custom error mode ?
2. Is that global.asax works on production server ?
 
0
 

Author Comment

by:hwsitservices
ID: 24848182
I set customErrors mode="Off", because I want to see if Response.Write("Found ERROR"); in the Application_Error event gets hit, it does not.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24850722
Make sure the ASP.NET runtime version on the production server is correctly set.
0
 

Author Comment

by:hwsitservices
ID: 24851358
Yes, it is set to 2.0.50727 same as my development server.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24851418
1. Can yo post your web.config file?

2. What does the stack trace say?


0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:hwsitservices
ID: 24851825
My Web.confid is below with slight changes for security reasons.

STACK TRACE (my forced exception):
[Exception: ERROR]
   ITU.Index.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Ed\My Documents\Visual Studio 2008\Projects\ITU\Index.aspx.cs:25
   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) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Why does the first line give the path to the file as it where on my local machine? This is the stack trace from the production server.
 

<?xml version="1.0"?>

<configuration>

	<configSections>

		<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

			<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

				<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

				<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

					<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

					<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

					<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

					<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

				</sectionGroup>

			</sectionGroup>

		</sectionGroup>

	</configSections>

  <appSettings>

  </appSettings>

	<connectionStrings>

	</connectionStrings>

	<system.web>

    <machineKey validationKey='XXXXXXXXXXX' 

decryptionKey='XXXXXX' validation='SHA1'/>

    <!-- 

            Set compilation debug="true" to insert debugging 

            symbols into the compiled page. Because this 

            affects performance, set this value to true only 

            during development.

        -->

		<compilation debug="true">

			<assemblies>

				<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

				<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

				<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

				<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

				<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

				<add assembly="System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

				<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>

		</compilation>

		<!--

            The <authentication> section enables configuration 

            of the security authentication mode used by 

            ASP.NET to identify an incoming user. 

        -->

    <authentication mode="Windows"/>
 

    <customErrors mode="Off" defaultRedirect="Error.aspx">

      <error statusCode="404" redirect="ErrorPageNotFound.aspx"/>

    </customErrors>

		<!--customErrors mode="Off"></customErrors-->

		<!--

            The <customErrors> section enables configuration 

            of what to do if/when an unhandled error occurs 

            during the execution of a request. Specifically, 

            it enables developers to configure html error pages 

            to be displayed in place of a error stack trace.
 

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">

            <error statusCode="403" redirect="NoAccess.htm" />

            <error statusCode="404" redirect="FileNotFound.htm" />

        </customErrors>

        -->

		<pages>

			<controls>

				<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

				<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

			</controls>

		</pages>

		<httpHandlers>

			<remove verb="*" path="*.asmx"/>

			<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

			<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

			<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>

		</httpHandlers>

		<httpModules>

			<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

		</httpModules>

	</system.web>

	<system.codedom>

		<compilers>

			<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">

				<providerOption name="CompilerVersion" value="v3.5"/>

				<providerOption name="WarnAsError" value="false"/>

			</compiler>

		</compilers>

	</system.codedom>

	<!-- 

        The system.webServer section is required for running ASP.NET AJAX under Internet

        Information Services 7.0.  It is not necessary for previous version of IIS.

    -->

	<system.webServer>

		<validation validateIntegratedModeConfiguration="false"/>

		<modules>

			<remove name="ScriptModule"/>

			<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

		</modules>

		<handlers>

			<remove name="WebServiceHandlerFactory-Integrated"/>

			<remove name="ScriptHandlerFactory"/>

			<remove name="ScriptHandlerFactoryAppServices"/>

			<remove name="ScriptResource"/>

			<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

			<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

			<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

		</handlers>

	</system.webServer>

	<runtime>

		<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

			<dependentAssembly>

				<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>

				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>

			</dependentAssembly>

			<dependentAssembly>

				<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>

				<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>

			</dependentAssembly>

		</assemblyBinding>

	</runtime>

</configuration>

Open in new window

0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24853469
How did you deploy your application to the production server?
0
 

Author Comment

by:hwsitservices
ID: 24854867
I publish it to a folder on my local machine the ftp those files to production server. This is how I have been deploying for two years.

In my Stack trace above do you have any idea why the first line gives the path to the file as it where on my local machine, not the production server?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24859299
It might sound very silly, but did you build your application before publishing it? You may want to try "Clean" solution, then Rebuild it, then Publish it.
0
 

Author Comment

by:hwsitservices
ID: 24860115
Tried that and get the same result. The Application_Error event still does not fire in Production.
0
 

Accepted Solution

by:
hwsitservices earned 0 total points
ID: 24875719
I found the answer here http://www.velocityreviews.com/forums/t300533-globalasax-not-firing.html. Needed to delete PrecompiledApp.config
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now