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

Sep 6th, 2009 | 3 Comments

Many a times you require to use both C-Sharp (C#) and Visual Basic (VB) code class files in the same project.

If you just place your both the code files in your App_Code directly this is the error you’ll see,

“The files ‘/BlogEngine.Web/App_Code/VBCode/Class1.vb’ and ‘/BlogEngine.Web/App_Code/CSCode/Extensions/BreakPost.cs’ use a different language, which is not allowed since they need to be compiled together.”

But you can get this done, here is a very simple way you can try that out,

1) First make two folders in App_code with foldernames as
- CSCode
- VBCode

2) Modify the Web.config with following code:

<compilation debug="false">
 <codeSubDirectories>
 <add directoryName="VBCode" />
 <add directoryName="CSCode" />
 </codeSubDirectories>
</compilation>