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.
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" %>
<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.
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:
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.
Anyone?
Bump...
How am I the only person with this problem?
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:
To something like this:
Then when your site starts up, ASP.NET loads your Global, rather than the regular UmbracoApplication global handler.
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.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:
It worked, I caused an error an it forwarded to espn.com.
Thanks.
is working on a reply...