Copied to clipboard

Flag this post as spam?

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


  • Rotem Orbach 121 posts 607 karma points
    Jan 10, 2019 @ 10:40
    Rotem Orbach
    0

    Global.asax - error fires twice

    Hi, I've implemented global.asax file, and I have two issues:

    1) from some reason, Global.asax.cs fils is never being hit. 2) I used a work-around to solve it (not that I like that). It looks like this:

    <%@ Application CodeBehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>
    
    <script RunAt="server">
        protected void Session_Start(object sender, EventArgs e)
        {
            // Session start logic here
        }
    
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var x = 1;
        }
    
        protected void Application_EndRequest(object sender, EventArgs e)
        {
        }
    
        protected void Session_End(object sender, EventArgs e)
        {
        }
    
        protected new void Application_Error(object sender, EventArgs e)
        {
            Exception ex = HttpContext.Current.Server.GetLastError();
            Umbraco.Core.Logging.LogHelper.Error(this.GetType(), ex.Message, ex);
        }</script>
    

    it works, BUT, the Application_Error event is being called twice!

    Please help, Rotem

  • Tor Langlo 191 posts 554 karma points
    Jan 10, 2019 @ 15:50
    Tor Langlo
    0

    Rotem, in my Global.asax I'm instead overriding the OnApplicationError method, and seems to be working fine:

    protected override void OnApplicationError(object sender, EventArgs e)
    {
      base.OnApplicationError(sender, e);
      if (Context.IsCustomErrorEnabled)
        GlobalErrorHandler.TransferToCustomErrorPage(this, e, ContentNavigator.CustomErrorPageUrl);
      if (!Request.IsLocal || Context.IsCustomErrorEnabled)
      {
        GlobalErrorHandler.SubmitException(Server.GetLastError());
      }
    }
    

    The content inside the method is just our implementation of course.

    -Tor

  • Rotem Orbach 121 posts 607 karma points
    Jan 10, 2019 @ 16:53
    Rotem Orbach
    0

    HI Tor, Thank you for the reply. I'll try that. do you happen to know why my .cs file code is not being fired. and I have to write my code in

    <script runat="Server">
    

    ?

    thanks

  • Tor Langlo 191 posts 554 karma points
    Jan 10, 2019 @ 17:00
    Tor Langlo
    0

    You know, I haven't actually tried that, but I think you'd have to place the codebehind file in the App_code folder. Maybe try this: CodeBehind=”~/App_Code/global.asax.cs” (and also place the file there of course).

    -Tor

  • Rotem Orbach 121 posts 607 karma points
    Jan 13, 2019 @ 07:50
    Rotem Orbach
    100

    Hi Tor, Unfortunately it doesn't work. :(

Please Sign in or register to post replies

Write your reply to:

Draft