Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Kneasel 22 posts 43 karma points
    Jun 02, 2014 @ 18:31
    Mark Kneasel
    0

    Application_Error and Global.asax.cs

    In previous non Umbraco .Net solutions we implemented custom error handling in the Global.asax code behind files Application_Error event and are trying to do something similar for our new Umbraco 7 project.  Could someone direct me how to do this in Umbraco 7 as none of my attempts have worked.  I tried adding a new code behind but the code was never hit.

  • Mark Kneasel 22 posts 43 karma points
    Jun 03, 2014 @ 15:56
    Mark Kneasel
    0

    I was able to figure out how to add an Application_Error method, but now it is being called twice for every error.  Anyone have any idea why this may be happening?

  • Andy Neil 4 posts 56 karma points
    Jun 16, 2014 @ 12:24
    Andy Neil
    0

    Hi Mark,

    How did you achieve this in the end? I've overridden UmbracoApplication but my "protected override void OnApplicationError(object sender, EventArgs e)" isn't getting hit.

    Thanks,
    Andy

  • Mark Kneasel 22 posts 43 karma points
    Jun 16, 2014 @ 13:41
    Mark Kneasel
    0

    Mine still appears to be getting called twice, which until I find out why I implented code to stop it from running the entire error routine twice. 

  • Yoni 49 posts 118 karma points
    Jul 26, 2014 @ 23:26
    Yoni
    0

    Mark: Can you please share your solution?

  • Mark Kneasel 22 posts 43 karma points
    Jul 28, 2014 @ 14:00
    Mark Kneasel
    0

    The temporary solutuon I have in place is a simple try catch block in the Application_Error procedure where I also clear the error the first time trhough.  This way the second call would not work so it goes to the catch block and does not execute all of the code.  I would still love to know why it is even called twice but I have already invested tons of time into that with no solution.  So if anyone knows about that please let me know.  If you need more info on my work around just let me know

  • Yoni 49 posts 118 karma points
    Jul 28, 2014 @ 14:08
    Yoni
    0

    You are one step ahead of me, I can't get the Application_Error procedure to fire.

     

    Can you pass along your code?

  • Mark Kneasel 22 posts 43 karma points
    Jul 28, 2014 @ 14:11
    Mark Kneasel
    0

    I cannot pass all of the code along.  Do you just want my Application_Error procedure?  I think your issue could be something in the web.config or Umbraco config as I too had a similar issue but do not remember how I fixed it.

  • Yoni 49 posts 118 karma points
    Jul 28, 2014 @ 14:12
    Yoni
    0

    Anything you can remember would help.

     

    Thanks

  • Mark Kneasel 22 posts 43 karma points
    Jul 28, 2014 @ 14:20
    Mark Kneasel
    0

    My Global.asax file looks like this:

     

    <%@ Application CodeBehind="~/App_Code/global.asax.cs" Inherits="Global" Language="C#" %>

    and then I have my Global.asax.cs file where the code behind runs.  I kind of remember the issue was originally that my .asax file was not referencing the CS file corretly
  • Haansi 51 posts 150 karma points
    Dec 05, 2014 @ 05:46
    Haansi
    0

    I m having same issue and also I m a little new to Umbraco. if i m correct in Umbraco 7 we don't have a global file. Is it ok if I add as Mark suggested ? will there be any issues ?

  • Haansi 51 posts 150 karma points
    Dec 05, 2014 @ 05:48
    Haansi
    0

    @Andy I have exectly same issue as you were facing. Can you please guide how you handled ? I have added event but on error its not being hit. Can you please help.

  • Andy Neil 4 posts 56 karma points
    Dec 05, 2014 @ 10:15
    Andy Neil
    3

    Yep, you can add a Global.asax, just make sure that the code file inherits the correct namespace, ie.

    <%@ Application Codebehind="Global.asax.cs" Inherits="YourNS.CustomGlobal" Language="C#" %>

    Then in the codebehind, something like:

    namespace YourNS
    {
        public class CustomGlobal : UmbracoApplication
        {
            protected override void OnApplicationError(object sender, EventArgs e)
            {
                var error = HttpContext.Current.Server.GetLastError();
                LoggingHelper.LogError(error);
            }
        }
    }
  • Haansi 51 posts 150 karma points
    Dec 06, 2014 @ 00:05
    Haansi
    0

    Thanks for replying Andy. Its a great help and I highly appropriate this community support :)

    cheers and have a great day.

  • Andy Neil 4 posts 56 karma points
    Dec 06, 2014 @ 15:14
    Andy Neil
    0

    Hey Haansi,

    You need to make sure that the Global.asax file declares the correct Inherits="" directive, depending on what namespace you have.
    That should also fix your route mapping issues.
    Cheers,
    Andy
  • Limberg Michelsen 22 posts 99 karma points
    Dec 10, 2014 @ 10:53
    Limberg Michelsen
    0

    I have the same problem

    Global.asax file:

    <%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>
    <script RunAt="server">
       void Application_Error(object sender, EventArgs e)
       {
    // Code to get the error message and send me an e-mail with the details.

    With every error, I get two identical error messages :/ What's happening? 

  • Nikhil 54 posts 166 karma points
    Mar 04, 2020 @ 11:57
  • Phil 54 posts 139 karma points
    Dec 11, 2014 @ 09:40
    Phil
    0

    I am also running into the issue with the Application_Error function firing twice with identical exceptions - does anybody have any ideas?

  • Nikhil 54 posts 166 karma points
    Mar 04, 2020 @ 11:56
  • Garrett Fisher 341 posts 496 karma points
    Dec 16, 2015 @ 16:49
    Garrett Fisher
    0

    I am working on a solution similar to Andy Neil's above -- but a dumb question for everyone -- with regard to the namespace / custom global class referred to in the Inherits="" attribute in Global.asax -- where should/does this class live? App_Code? I've got an override method I want to implement but i don't know where to put it!

    Thanks, Garrett

  • Alexandre Locas 52 posts 219 karma points
    Jul 18, 2018 @ 13:24
    Alexandre Locas
    0

    I got the same problem here : Global.asax.cs / Application_Error gets called 2 times with the same exception.

    Did anybody found out why ?

    Thank you

  • OXEN 4 posts 75 karma points
    Oct 05, 2019 @ 11:58
    OXEN
    0

    Umbraco Version : 8.0.0

    public class MyGlobalApplication : UmbracoApplicationBase
    {
    
        public MyGlobalApplication ()
        {
            //UmbracoApplicationBase is an abstract class            
            ApplicationEnd += MyGlobalApplication _ApplicationEnd;
    
        }
    
    
        private void MyGlobalApplication _ApplicationEnd(object sender, EventArgs e)
        { 
            //do whatever you like in here
        }
    
    }
    

    yw.

    -OXEN

Please Sign in or register to post replies

Write your reply to:

Draft