Global.asax not firing

Discussion in 'ASP .Net' started by furiousmojo, Jun 20, 2006.

  1. furiousmojo

    furiousmojo Guest

    This is a strange problem. I have a project where the contents of
    global.asax application_error are not firing. It is an asp.net 2.0
    application using web application projects. I have another app using
    web application projects and it's firing fine but it was upgraded from
    the 1.1 framework.

    Why doesn't my global.asax application_error routine fire?
     
    furiousmojo, Jun 20, 2006
    #1
    1. Advertisements

  2. can you produce some code to clearly demonstrate the problem? you can post
    here with the code once you have got it ready

    --
    ________________________
    Warm regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    Professional VSTO.NET - Wrox/Wiley
    The O.W.C. Black Book with .NET
    www.lulu.com/owc, Amazon
    Blog: http://www.msmvps.com/blogs/alvin
     
    Alvin Bruney [MVP], Jun 21, 2006
    #2
    1. Advertisements

  3. furiousmojo

    furiousmojo Guest

    Sure. This is the global.asax file:

    Imports System.Web.SessionState
    Imports cti.common
    Public Class Global_asax
    Inherits System.Web.HttpApplication

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the application is started
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session is started
    End Sub

    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
    EventArgs)
    ' Fires at the beginning of each request
    End Sub

    Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e
    As EventArgs)
    ' Fires upon attempting to authenticate the use
    End Sub

    Public Sub Application_Error(ByVal sender As Object, ByVal e As
    EventArgs)
    ' Fires when an error occurs

    Dim strDeveloperEmail As String

    Response.Redirect("/feedback.aspx")
    'asldkfj

    'If user is a developer, do Nothing, don't send e-mail, but
    show error message.
    If User.IsInRole(ConfigurationManager.AppSettings("DomainName")
    & "\" & ConfigurationManager.AppSettings("DevelopersGroupName")) = True
    Then
    'Otherwise just send e-mail and redirect to a friendly
    page.
    Else
    strDeveloperEmail =
    GetADEmailsOfGroupMembers("(&(ObjectClass=group)(sAMAccountName=" &
    ConfigurationManager.AppSettings("DevelopersGroupName") & "))")


    CustomSendEmail(ConfigurationManager.AppSettings("EmailFromName"), _
    ConfigurationManager.AppSettings("EmailFromAddress"), _
    strDeveloperEmail, _
    "", _
    "Portal Application Error", _
    BuildMessage(), _
    "Normal", _

    ConfigurationManager.AppSettings("InternalSMTPServerRelay"))

    Response.Redirect("/error.aspx")
    End If
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session ends
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the application ends
    End Sub

    Function BuildMessage() As String

    Dim strMessage As New StringBuilder

    strMessage.Append("Username: " &
    Request.ServerVariables("LOGON_USER"))
    strMessage.Append("<br>")
    strMessage.Append("IP Address: " &
    Request.ServerVariables("REMOTE_ADDR"))
    strMessage.Append("<br>")
    strMessage.Append("User Agent: " &
    Request.ServerVariables("HTTP_USER_AGENT"))
    strMessage.Append("<br>")
    strMessage.Append("Page: " & Request.Url.AbsoluteUri)
    strMessage.Append("<br>")
    strMessage.Append("Time: " & System.DateTime.Now)
    strMessage.Append("<br>")
    strMessage.Append("Details: " &
    Server.GetLastError().InnerException.ToString())
    Return strMessage.ToString

    End Function

    End Class

    as you can see, I have it redirect to /feedback.aspx just for testing
    to see if it's even running and it's not. Here's the code to create an
    unhandled exception:

    Dim dblTest As Double

    dblTest = ""

    Thanks in advance.
     
    furiousmojo, Jun 21, 2006
    #3
  4. re:
    It seems that you're not catching the right type of exception.

    Please review :

    http://msdn2.microsoft.com/en-us/system.web.httpunhandledexception_members.aspx
    http://msdn2.microsoft.com/en-us/system.web.httpunhandledexception.aspx
    http://msdn2.microsoft.com/en-us/system.web.httpexception.aspx
    http://msdn2.microsoft.com/en-us/system.web.httpcompileexception.aspx





     
    Juan T. Llibre, Jun 21, 2006
    #4
  5. furiousmojo

    furiousmojo Guest

    I don't think that's it. I have another 2.0 application with the exact
    same code and the global.asax file catches it and takes appropriate
    action. Maybe I just need to recreate the project?
     
    furiousmojo, Jun 22, 2006
    #5
  6. furiousmojo

    Guest Guest

    Did you get a resolution to this problem?
    I have the same problem too. All working fine on development machine, but
    Application_Error event doesn't fire on production machine. Other events are
    firing okay on production machine e.g. Session_Start.

    --
    Mark


     
    Guest, Jun 30, 2006
    #6
  7. furiousmojo

    furiousmojo Guest

    No I haven't. I haven't gotten around to try to recreate the project
    yet. That is my next step.


     
    furiousmojo, Jun 30, 2006
    #7
  8. furiousmojo

    furiousmojo Guest

    Recreating the project did not work. There's something to set on the
    production machine, but I can't find it. I've compared settings for
    IIS, web.config, between my working development and production machines
    to the new production machine and they're all the same. I've
    reinstalled asp.net 2.0, I've completed all critical updates. What
    else is there to try?

    Anyone have any ideas? Ugh.

     
    furiousmojo, Jul 12, 2006
    #8
  9. Please verify that your code conforms to accepted practices
    for capturing Application Error events per these articles :

    http://www.quepublishing.com/articles/article.asp?p=25171&rl=1
    (includes sample code)

    http://www.angrycoder.com/article.aspx?cid=5&y=2001&m=4&d=18
    (includes sample code)

    http://www.dotnetjohn.com/articles.aspx?articleid=42
    (includes sample code)





    Recreating the project did not work. There's something to set on the
    production machine, but I can't find it. I've compared settings for
    IIS, web.config, between my working development and production machines
    to the new production machine and they're all the same. I've
    reinstalled asp.net 2.0, I've completed all critical updates. What
    else is there to try?

    Anyone have any ideas? Ugh.

     
    Juan T. Llibre, Jul 12, 2006
    #9
  10. furiousmojo

    furiousmojo Guest

    I appreciate your help Juan. But again, the global.asax file fires
    just fine on my development machine and on another production machine.
    The code should be fine. Wouldn't you agree?

    There is something that is preventing it from firing on this particular
    production machine.
     
    furiousmojo, Jul 12, 2006
    #10
  11. re:
    Look for permissions issues.

    Make sure all the directories for the production machine have the
    proper permissions for the account which ASP.NET is running as, per :

    http://msdn2.microsoft.com/en-us/library/kwzs111e.aspx

    Make sure you know the correct account which
    ASP.NET is running as on that machine.

    If you have doubts as to which account that is, run this file :

    identity.aspx:
    -------------
    <%@ Page Language="VB" %>
    <%@ Import NameSpace = System.Security.Principal %>
    <script runat="server">
    Sub Page_Load()
    Dim tmp As String = WindowsIdentity.GetCurrent.Name()
    Label1.Text = tmp
    End Sub
    </script>
    <html>
    <head>
    <title>WindowsIdentity.GetCurrent.Name()</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
    </div>
    </form>
    </body>
    </html>
    --------

    Give the permissions outlined at:
    http://msdn2.microsoft.com/en-us/library/kwzs111e.aspx
    to whichever account is reported as the ASP.NEt account by "identity.aspx".

    Let us know what happens...





    I appreciate your help Juan. But again, the global.asax file fires
    just fine on my development machine and on another production machine.
    The code should be fine. Wouldn't you agree?

    There is something that is preventing it from firing on this particular
    production machine.
     
    Juan T. Llibre, Jul 12, 2006
    #11
  12. furiousmojo

    furiousmojo Guest

    Checked everything as per that document. It's running as NT
    AUTHORITY\NETWORK SERVICE and both this account and the asp.net account
    have the permissions as outlined by the document.

    Still no go. What on earth could this be... and apparently I'm not the
    only one as someone else posted in this thread with the same problem
    and I've seen it on the web elsewhere without a resolution.
     
    furiousmojo, Jul 12, 2006
    #12
  13. furiousmojo

    furiousmojo Guest

    And because it's somewhat relevant, I do have customerrors turned off.
    This is so I can let the global.asax handle what happens.

     
    furiousmojo, Jul 12, 2006
    #13
  14. furiousmojo

    Doug Guest

    This may be a silly question, but does the production machine have an
    ASP.NET user account? And do you see any errors in the Event Viewer
    (application log, system log, etc.)?
     
    Doug, Jul 12, 2006
    #14
  15. furiousmojo

    furiousmojo Guest

    Yes, the ASP.NET account exists and was verified against with the
    permissions document Juan posted.

    I think I just fixed it... and it was so simple. I'm not sure exactly
    why it fixed it yet, but it's working now. I simply deleted all of the
    contents of the folder and reuploaded it. There must've been some file
    present that was causing the problem.
     
    furiousmojo, Jul 12, 2006
    #15
  16. furiousmojo

    Doug Guest

    Glad it's working. Chalk one up for a clean slate!
     
    Doug, Jul 12, 2006
    #16
  17. furiousmojo

    furiousmojo Guest

    PrecompiledApp.config was the culprit. Exclude/delete this from the
    project and problem is solved! Wow.
     
    furiousmojo, Jul 12, 2006
    #17
  18. re:
    That is a bit confusing.
    They should refer to the *same* account.





    Checked everything as per that document. It's running as NT
    AUTHORITY\NETWORK SERVICE and both this account and the asp.net account
    have the permissions as outlined by the document.

    Still no go. What on earth could this be... and apparently I'm not the
    only one as someone else posted in this thread with the same problem
    and I've seen it on the web elsewhere without a resolution.
     
    Juan T. Llibre, Jul 12, 2006
    #18
  19. I'll certainly make a note of that!

    Glad to know you're up and running again!
     
    Juan T. Llibre, Jul 12, 2006
    #19
  20. furiousmojo

    sherlock Guest

    Strange, I had the same error, where the events in the Global.asax.cs
    were not firing. After more than a month of puzzling through this, I
    eventually fixed this by including PrecompiledApp.Config on the server.
     
    sherlock, Jul 27, 2006
    #20
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.