Thursday, July 1, 2010

How Google Works

Ever wonder how Google really works? This is a fun little flow chart published by PPCBLOG that shows you how much goes on behind the plain white background and colorful graphic every second of every day and how fast the Google machine finds new websites, indexes them, rates them and presents them to users searching for a particular string on the internet.

How Google Indexs Searches Works?
Click Picture To Enlarge

Easy Way To Email Errors From Your ASP.Net Site To You

Errors on your site are never good, but it's best when you know about them the second they happen rather than a user telling you- or worse- not telling you.

This is a quick a dirty method I use for emailing myself details about errors when they occur on my sites.

If you don't already have one, add a Global Application Class (Global.asax) to your site. It should come with a sub procedure named Application_Error, but if it doesn't go ahead and create one. In the code I've provided below, I use a custom email class I use to templatize my emails, but you can easily adapt it to any email class you choose.

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs

Dim mm As New MMEmail()
mm.ToRecipients.Add("")
mm.Subject = "[ERROR] " & Request.Url.AbsoluteUri.ToString

Dim ex As Exception = Server.GetLastError().GetBaseException()
Dim body As String = ""

'Get URL where error occured
body &= "[URL]"
body &= "<br/>"
body &= Request.Url.AbsoluteUri.ToString
body &= "<br/>"
body &= "<br/>"

'Brief message of what went wrong and line where error occured in code.
body &= "[MESSAGE]"
body &= "<br/>"
body &= ex.Message.Replace(vbCrLf, "<br/>")
body &= "<br/>"
body &= "<br/>"

body &= "[SOURCE]"
body &= "<br/>"
body &= ex.Source.Replace(vbCrLf, "<br/>")
body &= "<br/>"
body &= "<br/>"

body &= "[STACK TRACE]"
body &= "<br/>"
body &= ex.StackTrace.Replace(vbCrLf, "<br/>")
body &= "<br/>"
body &= "<br/>"

mm.Body = body
mm.Send()
End Sub


Obviously, you'll need to add your email address in and use either the default email class or another class if you'd prefer. You'll need the email to be set up in the web.config - which may be another good topic I could touch on another time. And then, it wouldn't hurt to go intentionally create an error. I made a blank page with the on load function that calls a function s() which doesn't exist:
Public Sub Form_Load() Handles Me.Load
s()
End Sub


If your VB.NET Application won't run on Windows 7

Despite being primarily a web developer, every now and then at my office, I need to create small little Windows Form based applications that perform one or two simple tasks to help out the every day processes of the staff.

Recently a couple people at our office were upgraded to Windows 7, and have experienced issues with those Visual Studio 2008 based applications, either during installation or running them after installing.

After some investigation, I stumbled upon the cause of the problem and a solution. Whether it is the machine or the operating system or gremlins sneaking around in this guy's new computer; for some reason, code compiled to work with the Target CPU value "AnyCPU" won't run on this machine.

To correct the issue, I opened the project settings in Visual Studio and clicked through to the Advanced Compiler Settings:
Project -> Compile -> Advanced Compile Options

Change the "Target CPU" field to "x86" and click OK.
Publish your application and it should install and run on the Windows 7 computer now.


Windows 7 Visual Studio 2008 Project Settings Target CPU