Posts

Showing posts from October 13, 2013

Save yourself hours of debugging time in an ASP.NET web site/app.

Image
If you are working on a web application that has added code to the Global.asax that logs and clears all unhandled exceptions, down the road in the development/maintenance unit test cycle you may forget to check that any errors have occurred during your live testing and can’t figure out why your application isn’t working correctly.  To prevent this from happening to you and other developers on your project add a Debug.Assert message just before the code that logs the unhandled exception. For example: Debug.Assert( False , String .Format( "Exception about to be logged to database:{0}" , unhandledException)) Then when you are running in debug mode and an unhandled exception occurs you will get a popup like this:

ASP.NET 2.0 page lifecycle

Every once in a while the ASP.NET 2.0 page lifecycle doesn’t quite work as I thought and I have to re-research it again. Here is a link I found that helped me this time. What was of special note to me this time was that a web user control will not have created its child controls until the page.OnPreRenderComplete event. Which, makes complete sense to me now. http://blogs.thesitedoctor.co.uk/tim/2006/06/30/Complete+Lifecycle+Of+An+ASPNet+Page+And+Controls.aspx

Fixing HTTP Error 401.1 in IIS 7.5 on Windows 7

For a test I was trying to run a website on my local Windows 7 machine in IIS 7.5.  I put the website files in my C:\inetpub\wwwroot\MyWebsite. I opened IIS 7.5 and right-clicked on Sites and selected "Add Web Site". In the "Add Web Site" dialog I entered the "Site name", "Physical path" as above and "Host name" and clicked "OK". For the "Select Application Pool" dialog I selected "Classic .NET AppPool" which is .Net 2.0 with Classic Pipeline. I double clicked on "Authentication" and disabled everything and enabled "Windows Authentication" as this is a local intranet website. In "Application Pools" I went into "Advanced Settings" for the "Classic .NET AppPool" and changed the Identity to "Custom account" and entered "my companies domain\my userid" and password, because that is how the website is run on the corporate server unde

VS 2008 Next Error keyboard shortcut

When I’m refactoring some code if there is an interface change I usually make the interface change first and then fix all the error’s that come up.  Using the mouse to go to the errors window and double click on the next error can get tedious so I did some research to figure out a better way and found there is a keyboard short cut "ctrl-shift-F12" in VS 2008 that will take you to the next error. For more information on keyboard short cuts check this out: http://www.mobydisk.com/softdev/techinfo/dotnetkeyboard.html

Microsoft .NET: Architecting Applications for the Enterprise

Image
The book Microsoft® .NET: Architecting Applications for the Enterprise: Architecting Applications for the Enterprise (PRO-Developer) by Dino Esposito and Andrea Saltarello is written for Programmers/Application Architects to use the latest state of the industry .NET techniques and technologies for software development. They provide very clear explanations of the technologies and techniques like WCF, Entity Framework, Domain Driven Design etc. Excellent examples of when and where to use each technology and technique and when not to use them. They clearly reference where each technique came from and how to find more information. For me it had just the right amount of code examples and written explanations.  Buy a copy today.

Speed Improvement by avoiding exceptions

Image
I learned a neat thing.  If you press ctrl-alt-e in Visual Studio you bring up this dialog: Then check the Thrown checkbox for "Common Language Runtime Exceptions" like this: Then run the project in debug mode and if an exception occurs the run will break at that point in the code and you can examine what happened.  This is great for finding uncaught exceptions and improper use of exceptions like this:                 Try                     If c.Contains( "somestring" ) Then Stop                 Catch ex As NullReferenceException                 End Try One should never do this because it is extremely inefficient.  Exceptions are costly and should always be avoided if possible.  In this case we can avoid this exception by checking c for nothing, like so:             If Not IsNothing(c) Then                 If c.Contains( "somestring" ) Then Stop             End If

VB.NET How to time a section of code.

Once in a while I want to see how long a section of code takes to run and I always forget the best way to do this. endTime .Subtract( s tartTime).TotalMilliseconds() It's so simple it's easy to forget I guess.

How to check if a datetime field equals current date in SQL Server Transact SQL

Had to write a SQL Server query to check if a date is the current day. After some searching I found a good way of doing it here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=38012 SELECT * FROM table WHERE DATEDIFF(day, StartDate, GETDATE()) = 0