Welcome to Windows Communication Foundation (WCF)
Top Tasks :

WCF Community Bloggers

Monday, August 04, 2008 - Posts

  • Better exception reporting in ASP.NET part 2

    This is the third post in a series. The first post described the problem: ASP.NET wasn't reporting inner exception stack traces. The second post described my solution. This post shows the code I used to solve the problem: a custom email provider for the Health Monitoring system in ASP.NET. Enjoy! Here's the provider. Note that I opted *not* to build a buffering provider to keep things simple: public class MyMailWebEventProvider : WebEventProvider { string to; string from; string subjectPrefix; public override void Initialize( string name, NameValueCollection config) { base .Initialize(name, config); to = GetAndRemoveStringAttribute(config, "to" , true ); from = GetAndRemoveStringAttribute(config, "from" , true ); subjectPrefix = GetAndRemoveStringAttribute(config, "subjectPrefix" , false ); } public override void ProcessEvent(WebBaseEvent raisedEvent) { SendMail(raisedEvent); } private void SendMail(WebBaseEvent raisedEvent) { string subject = ComputeEmailSubject(raisedEvent); string body = ComputeEmailBody(raisedEvent); MailMessage msg = new MailMessage(from, to, subject, body); new SmtpClient().Send(msg); } private string ComputeEmailBody(WebBaseEvent raisedEvent) { WebRequestErrorEvent errorEvent = raisedEvent as WebRequestErrorEvent; if ( null != errorEvent) return ErrorEventFormattingHelper.FormatRequestErrorEvent(errorEvent); else return raisedEvent.ToString(); } private string ComputeEmailSubject(WebBaseEvent raisedEvent) { StringBuilder subjectBuilder = new StringBuilder(); // surface some details in subject about error events WebBaseErrorEvent errorEvent = raisedEvent as WebBaseErrorEvent; if ( null != errorEvent) { Exception unhandledException = errorEvent.ErrorException; // drill through reflection exceptions to show the root cause TargetInvocationException invocationException = unhandledException as TargetInvocationException; if ( null != invocationException) { Exception innerException = DrillIntoTargetInvocationException(invocationException); subjectBuilder.AppendFormat( "{0}" , (innerException ?? invocationException).GetType().Name); if ( null != innerException) subjectBuilder.Append( " (via reflection)" ); } else subjectBuilder.Append(unhandledException.GetType().Name); } // if we've not got anything better // just show the event type in the subject if (0 == subjectBuilder.Length) subjectBuilder.AppendFormat( "Event type: {0}" , raisedEvent.GetType().Name); if (! string .IsNullOrEmpty(subjectPrefix)) Read More...
  • CSLA Light Prerelease 2 available

    I've put another prerelease of CSLA Light (CSLA for Silverlight) and CSLA .NET 3.6 online at www.lhotka.net/cslalight/download.aspx . Check out the new identity base classes in Csla.Security and Csla.Silverlight.Security - they are pretty darn cool! Check out the new Validator UI control - I think that is really cool!! It won't keep that name, because we're merging the Authorizer functionality directly into that control, so the result will be a consolidated control that does both things - we don't have a name for it yet... I'm pretty sure the ClientContext and GlobalContext work right, but the unit tests don't show that - so I'd recommend viewing that functionality with suspicion. I know some of the security tests don't work. Authentication is still evolving and some of the test apps are lagging a bit behind. Please remember, these are very early preview builds. They are not stable. They are not complete. They may or may not work for you. They are not supported. We have found, in testing, that Silverlight Beta 2 is not entirely stable. And that WCF in Silverlight is particularly unstable . If you run the unit tests in Silverlight you'll probably find what we find - that they randomly fail sometimes. They'll run. They'll fail. Then they'll run again. With no discernable pattern. Quite frustrating, but I guess this is the nature of working on a beta platform. I have also put the sample app I've been blogging about at http://www.lhotka.net/files/cslalight/SimpleCslaLightAppvb-080803.zip . This sample app shows all the things I've talked about in my Part 1 and Part 2 posts, and I'll be coming out with more posts in the series in the next few days. Read More...

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us