Google+ Peter Bromberg's .NET Blog | All Things Programming

Peter Bromberg's .NET Blog All Things Programming

Two Useful Debugging Tricks Most Developers Don't Know

7. August 2016 16:22 by admin in

1. Put in a Global Unhandled Exception handler in your ASP.NET / MVC applications:


There are many places where developers don't handle exceptions. Use the above code and set a breakpoint where shown. Any time an unhandled exception is thrown, your breakpoint will be hit. You can examine the eception and look at the stack trace portion to see exactly what went wrong.


2. Turn on exact debugger breaking in Exception Settings


At the top menu, choose Debug/Windows/Exception Settings. (Ctrl-D, E) Make suyre the "Common Language Runtime Exceptions" Is fully checked. What this does is that whenever an exception is generated, the debugger will break at the exact line where the exception was thrown, making your job both easier and more efficient.

Here's to using your noggin' as a developer!

How to Ensure that jQuery is only loaded once

26. July 2016 13:50 by admin in ASP.NET, C#, Jquery

Often we have pages and master pages and "bundles" that load scripts like jQuery and we can't always be sure that a particular page already has it loaded. Here is a script that will only inject jQuery into a page if it has not already been loaded:


<!-- comment or uncomment next line to test it out --->
<script src=''></script>


// Only do anything if jQuery isn't defined

if (typeof jQuery == 'undefined') {

function getScript(url, success) {

var script = document.createElement('script');

    script.src = url;

var head = document.getElementsByTagName('head')[0],done = false;

// Attach handlers for all browsers

script.onload = script.onreadystatechange = function() {

if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {

done = true;

// callback function provided as param


script.onload = script.onreadystatechange = null;







getScript('', function() {

if (typeof jQuery=='undefined') {

// Super failsafe

} else {

alert("We Loaded it!");

// jQuery loaded 




} else { 

// jQuery was already loaded

alert("jQuery is Already Loaded!");

// Run your jQuery Code









How to Use OrmLite's SelectMulti Feature

10. July 2016 15:07 by admin in

 using (var db = new SqlConnection(ConfigurationManager.ConnectionStrings["TEST"].ConnectionString))



                OrmLiteConfig.DialectProvider = SqlServer2012OrmLiteDialectProvider.Instance;

                OrmLiteConfig.DialectProvider.NamingStrategy = new OrmLiteNamingStrategyBase();


                var q = db.From<Customer>()

                       .Join<Customer, Order>((cust,ord)=>cust.CustomerID==ord.CustomerID)

                       .Join<Order,Order_Detail >((ord,orddet)=>ord.OrderID==orddet.OrderID);

                var results = db.SelectMulti<Customer, Order_Detail, Order>(q);


How To Fix "Unable to access the IIS Metabase" error when loading Web Application in Visual Studio

23. May 2016 06:58 by admin in

When you see:

<Path to Project> : error  : The Web Application <Project Name> is configured to use IIS.  Unable to access the IIS metabase. You do not have sufficient privilege to access IIS web sites on your machine.

There is an easy fix:

Browse to C:\Windows\System32\inetsrv and then double-click the “config” directory. You should get this warning dialog:


Click Continue, then do the same for the C:\Windows\System32\inetsrv\config\export directory and the other directories in C:\Windows\System32\inetsrv

This should fix the issue and you will be able to load the project.