Advanced Error Reporting in Umbraco, dasBlog and other ASP.Net sites
Friday, February 27, 2009 3:51:13 PM (GMT Standard Time, UTC+00:00)
If you've been following my blog you'll know that I've been raving about error reporting within ASP.Net (you can see my ASP.Net Error Reporting category for a couple of them if you like) but until now it's been limited to those sites that you have access to the global.asax file.
One of the irritations I've found with Umbraco and dasBlog is that I don't get notified of errors as they're just logged to a text file/database somewhere. This is fine if you run 2 or 3 sites but we manage too many to check them all everyday. Instead we rely on email error notifications which until today have been a PITA to integrate into Umbraco.
Today I'd like to introduce to you Error Handling v2.0 which instead of relying on the global.asax file for the error hooks, uses a HttpModule which means you can install it into any existing/pre-built application such as Umbraco and dasBlog.
Adding it into the site is simple, you'll need to install the module into the web.config file and add the configuration section a sample (cut down) web.config is below:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="tsdErrorsConfigSection" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<tsdErrorsConfigSection file="ErrorHandling.config"/>
<system.net>
<mailSettings>
<smtp from="you@yourdomain.com">
<network host="127.0.0.1" port="25" />
</smtp>
</mailSettings>
</system.net>
<system.web>
<httpModules>
<add name="ErrorModule" type="TheSiteDoctor.ErrorHandling.ErrorModule, TheSiteDoctor.ErrorHandling" />
</httpModules>
</system.web>
<!--...-->
<!--
IIS 7 Settings
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<add name="ErrorModule" type="TheSiteDoctor.ErrorHandling.ErrorModule, TheSiteDoctor.ErrorHandling" />
</modules>
</system.webServer>
-->
</configuration> Then you'll need to check all the settings -I recommend storing these in another .config file for clarities sake. Make sure you've configured your SMTP settings and you should be good to go.
If you want to test your settings, I've included a test page for you that will check your settings and show you the defaults if you've not set them. I've got this running now on a couple of Umbraco and dasBlog installs without an issue.
There's also a useful logging system in it which I'll look to overview in a later post but if you want to see it, check out the included aspx file.
Download ErrorHandling_v2.0.zip (25Kb)
If you do use this code I'd be interested to hear how you get on, I think it requires a little more refinement un some areas but it's pretty robust.
Enjoy.
No hidden charges
Wednesday, February 25, 2009 6:36:42 PM (GMT Standard Time, UTC+00:00)
I've had a couple of situations recently where clients have suggesting "tricking" the user into either remaining subscribed to a service i.e. a mailing list or rammed some sales info down their throat whereas we advise to go the oposite direction -if someone doesn't want to read your email, why pay to send it to them? Just because you send it to them, doesn't mean they're going to read it.
Then while booking some tickets this evening I came across FlyThomson's take on it. I was going to blog how I thought their prices were reasonable, or how their checkout process upsold well etc but instead I get to the very last stage and after having "Still no change, the seats are the same price"!"/"The price you see is the price you pay" throughout I noticed that when selection any form of "grown up" payment card I get charged £10!!
The only cards it turns out that don't charge you are Solo and Visa Electron. So much for the "Still no change."
Why try and bamboozle your customer? Ok I had to pay it but I wouldn't now recommend you.

Thanks. Why didn't you state that at the start?
Recent comments macro for DasBlog
Tuesday, February 17, 2009 9:25:05 AM (GMT Standard Time, UTC+00:00)
One of the issues I had with John Forsythe's Recent Comments macro for DasBlog was that the dasBlog recent comments weren't ordered by date (descending). I found that as people commented on older posts they were getting buried which irritated me as many were very still valid comments.
The fix was actually fairly simple, it was just a matter of adding a sort and thanks to Lamba expressions, this is something we can do fairly simply. If you want to add recent comments to your dasBlog installation, use the following macro:
Recent Comments Macro
public virtual Control RecentComments(
int count,
int adminComments,
int trimTitle,
int trimContent,
int trimAuthor,
bool showTitle,
bool showCommentText,
bool showCommentCount)
{...} 
{
int commentsToShow;
int totalComments;

CommentCollection allComments =
this.requestPage.DataService.GetAllComments();

totalComments = allComments.Count;
//Sort the comments in date order (descending) 
allComments.Sort((c1, c2) => c1.CreatedUtc.CompareTo(c2.CreatedUtc));
if (!
this.requestPage.HideAdminTools && SiteSecurity.IsInRole(
"admin"))

commentsToShow = totalComments - adminComments;
else 
commentsToShow = totalComments - count;
if (commentsToShow <
0)

commentsToShow =
0;

StringBuilder sb =
new StringBuilder();

sb.AppendLine(
"<div class=\"recentComments\">");
if (showCommentCount)

sb.AppendFormat(
"<div class=\"totalComments\">Total Comments: {0}</div>", totalComments);

sb.AppendLine(
"<ul class=\"comments\">");
Loop through the comments
#region Loop through the comments
for (
int i = totalComments -
1; i >= commentsToShow; i--)
{...} 
{

Comment current = allComments[i];
bool showComment;
if (!current.IsPublic || (current.SpamState == SpamState.Spam))
{...} 
{
if (!
this.requestPage.HideAdminTools && SiteSecurity.IsInRole(
"admin"))
{...}
else
{...} 
{

showComment =
false;
if (commentsToShow >
0)

commentsToShow--;

}

}
else
{...}
if (showComment)
{...} 
{
if ((current.SpamState == SpamState.Spam))

sb.Append(
"<li class=\"spam\">");
else if (!current.IsPublic)

sb.Append(
"<li class=\"hidden\">");
else 
sb.Append(
"<li>");
string link =
String.Format(
"{0}{1}{2}", SiteUtilities.GetCommentViewUrl(current.TargetEntryId),
"#", current.EntryId);
string title = current.TargetTitle;
string desc = current.Content;
string author = current.Author;
if (showTitle)
{...} 
{

sb.AppendFormat(
"<div class=\"recent{0}CommentsTitle\"><a href=\"{1}\">",

current.SpamState,

link

);
if ((title.Length > trimTitle) && (trimTitle >
0))

sb.AppendFormat(
"RE: {0}...", title.Substring(
0, trimTitle));
else 
sb.AppendFormat(
"RE: {0}", title);

sb.Append(
"</a></div>");

}
if (showCommentText)
{...} 
{

sb.AppendFormat(
"<div class=\"recentCommentsContent\"><a href=\"{0}\">",

link

);
if ((desc.Length > trimContent) && (trimContent >
0))
{...} 
{

sb.Append(desc.Substring(
0, trimContent));

sb.Append(
"...");

}
else
{...}

sb.Append(
"</a></div>");

}

sb.Append(
"<div class=\"recentCommentsAuthor\">");
if ((author.Length > trimAuthor) && (trimAuthor >
0))
{...} 
{
int num3 = (trimAuthor > author.Length) ? author.Length : trimAuthor;

sb.Append(
"by " + author.Substring(
0, num3));

sb.Append(
"...");

}
else
{...} 
{

sb.Append(
"by " + author);

}

sb.Append(
"</div></li>");

}

}
#endregion

sb.AppendLine(
"</ul>");

sb.AppendLine(
"</div>");
return new LiteralControl(sb.ToString());

}
I've since been working on extending it further so you can add a "All Comments" link which I'll post up later as it needs a little more work :)
If you want this wrapped up as a DLL let me know and I'll upload it.
Update 26th Feb 2009: You can download the dll here (it's also got a few other things in there if you want to look around).
Update 27th Feb 2009: I noticed that the above code was messing up everynow and again so I've updated it to use Linq instead which seems to work well. I've updated the DLL but not the source yet.
Can Twitter be a bad thing for your business?
Monday, February 09, 2009 10:26:45 PM (GMT Standard Time, UTC+00:00)
There's going to be a series of articles shortly that go into my attempts of using social networking to build your business but I thought I'd get this one out into the blogosphere first.
What with the recent onslaught of "celebrities" onto Twitter such as Stephen Fry (who incidentally p'd a lot of people off the other day while over-posting), Chris Moyles and David Allen to mention a few, it got me thinking whether Twitter can actually be a negative thing for you and/or your business. I'm not referring to the tremendous time you lose reading and responding to the numerous posts (Tweets) but more about the transparency issues you'll run into.
Those of you who know me in person know that I don't tend to bite my tongue (not always a good thing I can tell you!) and instead tend to speak openly and honestly regardless of the situation, so for me I don't really worry about what I Tweet, IM, e-mail or SMS as it's usually saying the same thing (unless I'm tired and losing my mind!). I have however noticed that's not true for everyone.
For me, Twitter, MSN and these other social-status update services such as Facebook bring a whole new layer of complexity to those who want to "skive" -who hasn't seen the notorious Kyle Doyle email. It's not so much full on lies like Kyle's that I'm referring to but more the little ones like saying you couldn't complete some work because of xyz and then having posted a message on Twitter along the lines of "sod this I'm off to the pub". When your employer (or even friend) see's that, if it doesn't immediately annoy them, it will certainly plant the seed of doubt in their mind.
I've been seeing this "phenomenon" for a while, it started with MSN status updates, then Facebook and now the worst of them all -Twitter. For goodness sake, just be honest, if you lie these days you're so much more likely to be caught out and that really can ruin your reputation -or at least lose you business.