Copied to clipboard

Flag this post as spam?

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


  • Yoni 49 posts 118 karma points
    Jul 28, 2014 @ 16:32
    Yoni
    0

    Creating Custom Application_Error procedure in Umbraco 7 (vb)

    I am in the process of moving my site over from standard asp.net to Umbraco. One thing I must have is access is to the Application_Error procedure that is in the global.asax. I have been told that it is not a good idea to access the global.asax directly in Umbraco as there "is a lot going on". I was helped on another form and I have gotten this far:

    Imports Microsoft.VisualBasic
    Imports Umbraco.Core
    
    
    Public Class MyCustomEvent1
    Inherits ApplicationEventHandler
    
    
    Protected Overrides Sub ApplicationStarted(umbracoApplication As UmbracoApplicationBase, applicationContext As ApplicationContext)
    
        AddHandler umbracoApplication.[Error], AddressOf umbracoApplication_Error
         MsgBox("test")      
    End Sub
    
    Private Sub umbracoApplication_Error(sender As Object, e As EventArgs)
        Dim x As HttpContext = HttpContext.Current
        x.Response.Redirect("http://www.espn.com")
        // Do your stuff
    End Sub
    End Class
    

    I debugged it locally and the first procedure is running (I get the popup). However when I create either a 404 error or a 500 error, the umbracoApplication_Error procedure does not run. I presume one of 2 things, either the code is wrong or there is somethign else catching the error first.

    Can someone please help?

    Thanks.

  • Yoni 49 posts 118 karma points
    Aug 18, 2014 @ 22:29
    Yoni
    0

    Anyone?

  • Yoni 49 posts 118 karma points
    Sep 07, 2014 @ 11:19
    Yoni
    0

    Bump...

    How am I the only person with this problem?

  • Jamie Howarth 306 posts 773 karma points c-trib
    Sep 08, 2014 @ 15:38
    Jamie Howarth
    100

    Hi Yoni,

    A better way of accessing the UmbracoApplication.Error event is to add your own Global.asax.vb class, which then inherits Umbraco.Web.UmbracoApplication.

    Then in the OnApplicationStarted event, you can call AddHandler to the Application.Error event to your own delegate.

    When you add a Global.asax.vb code-behind, ensure that you update this line in the Global.asax:

    <%@ Application Codebehind="Global.asax.vb" Inherits="Umbraco.Web.UmbracoApplication" Language="VB" %>
    

    To something like this:

    <%@ Application Codebehind="Global.asax.vb" Inherits="Your.Custom.Global" Language="VB" %>

    Then when your site starts up, ASP.NET loads your Global, rather than the regular UmbracoApplication global handler.

  • Sebastiaan Janssen 5044 posts 15475 karma points MVP admin hq
    Sep 08, 2014 @ 15:42
    Sebastiaan Janssen
    0

    I'm hoping this might help: http://www.wiliam.com.au/wiliam-blog/sydney-web-design-custom-error-pages-with-http-status-codes-in-umbraco

    Specifically the <httpErrors existingResponse='PassThrough' /> in umbracoSettings.config could be something that's going to help you.

  • Yoni 49 posts 118 karma points
    Sep 29, 2014 @ 10:36
    Yoni
    0

    Thank you Benjamin.

    My solution.

    I removed the existing Global.asax (the C# one)

    I added a Global.asax VB one.

    The contents of the file are:

    <%@ Application Codebehind="Global.asax.vb" Inherits="Umbraco.Web.UmbracoApplication" Language="VB" %>
    
    <script runat="server">
    
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    
        Response.Redirect("http://www.espn.com")
    
        ' Code that runs when an unhandled error occurs
    
    End Sub
    </script>
    

    It worked, I caused an error an it forwarded to espn.com.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft