Global Class
Remove Empty Methods

Mar 20

It's not uncommon to add a global.ascx file to a project. By default, it adds a series of empty methods which you can use but are often left empty. Recently I came across an error on my site which was new to me, hard to reproduce yet fixed with a page refresh.

In all honesty I can not remember what the error message was and I wasn't able to reproduce it. I tried looking through my site monitoring but had no luck there. (I had left the investigation too late), but I do recall that it had to do with images, cache and my CDN. Not very helpful for people searching for the error but hopefully someone will capture it for me and let me know.

The error was fixed by removing the page from the cache and reloading it and I saw it a total of about three times.

By Chance

It just so happened that not long after encountering these errors that I then read a blog post, (I am sure it was a MSDN post by a Microsoft employee), that mentioned an ASP.NET issue with empty methods in the global.ascx class and it's interference with CDN services causing application errors. I have assumed that this was the cause of my issue.

Another thing to consider. If the methods are present and empty then the page lifecycle looks to execute them by adding them to the page life cycle and this just wastes time. If you have empty methods in your global.ascx file then remove them.

I am usually one to push for the removal of empty methods or unused code from a project and was surprised that I was doing this with all my projects so I find myself, telling myself off. If you are not using the method inside your global.ascx file then delete it. They only slow your page's performance down and potentially can cause an application error's with CDN services. (I am sure I wasn't dreaming the article up.) Since doing this, I haven't seen this error again.

Darrin Robertson - Sitefinity Developer

Thanks for reading and feel free to comment
Darrin Robertson

Leave a comment
Load more comments

Make a Comment

Please type the code above