Sep 7th, 2009 | No Comments

The following code snippet will help you to catch an error in the global.asax file,

Turn off the custom error mode in web.config file first,

<customErrors mode="Off">

And add this code in your global.asax file to catch the error,

void Application_Error(object sender, EventArgs e)
 {
 HttpContext context = ((HttpApplication)sender).Context;
 if (context.Error != null)
 {
 Exception ex = context.Error;
 string msg = string.Empty;

 while (ex != null)
 {
 if (!string.IsNullOrEmpty(ex.Message))
 msg += ex.ToString() + "<br /><br />";
 ex = ex.InnerException;
 }
 context.Response.Clear();
 context.Response.Write(msg);
 context.Response.End();
 }
 } 

Hope this helps :)

Written by Ajay Matharu

September 7th, 2009 at 9:53 am

Jul 22nd, 2009 | No Comments

Another one of those problems that can stump you for a while. I often make backups of files as I progress and sometimes leave them in the website folder, this was fine with classic ASP but as I have found with ASP.Net can cause all sorts of problems.One issue I was having was trying to reference a component in my aspx page from the codebehind page and seeing the following error when trying to reference a label control:

“Label2 does not exist in the current context”

So I found that the problem was even though I renamed one of my old files it still contained the class that my codebehind was referencing (i.e. the class names were still the same) – and therefore was not seeing the newly added Label control to my new code.Shame the compiler doesn’t realise the duplication and give some indication.

Lesson: Remove any backed up files from the web folder and/or build directory to avoid pain )

Written by Ajay Matharu

July 22nd, 2009 at 11:24 pm

Page 1 of 212