Mail Templates for ASP.NET MVC

I was working on an MVC project recently, and wanted to use templates for formatting emails.  Scott Hanselmann recommends MvcMailer in this post.  I gave it try, but it has a couple dependencies on other projects, and I wanted to keep it simple and pragmatic for this small project.  

I ended up using ActionMailer.Net which uses two of its own dlls and no external dependencies.  ActionMailer worked for my needs and uses standard views, either .aspx or Razor view files.

Prior to MVC, in web forms, I built an Email Templater, which allowed me to create a new model for each email view, but I had to point the templater to the correct template file location.  ActionMailer is essentially an extension of the MVC ControllerBase class, so all you need to do is place your view files in the View folder of your site.

For my needs it worked, but it is a very basic email requirement I have, so it is possible I may run into obstacles.  But, so far so good.

Tags:

 

Access Session in HttpHandler

I have run into this one several times now, and want to make a note of it.

I sometimes create .NET Http Handlers that need to access session variables.  HttpHandlers are .NET class that implement the IHttpHandler interface.  By default these classes will throw an error if you try to use the Session object at all.

You can easily enable Session access by implementing the IRequiresSessionState interface.

public class VehicleIdCard : IHttpHandler, IRequiresSessionState {

    public void ProcessRequest (HttpContext context) {
          string myVar = context.Session["MySessVar"];
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

Tags:

 

Google Guitar Logo - in honor of Les Paul

[EDIT: Looks Google has disable the Google Guitar links so my compositions below no longer work.  Bummer.]

The Google logo today is very cool.  It is in honor of the guitarist Les Paul who is well known for the Gibson guitar model which bares his name, the Gibson Les Paul.

The great thing about the Google logo is that you can actually PLAY the guitar.  Even more, you can record yourself and send your friends links to your compositions!  It will be interesting to see what people come up with.

So far, I have discovered that the Google guitar is in the key of G.  The strings are laid out such that it is easy to play whole chords.  I was able to determine the notes of a major scale.

The Google guitar's scale starts on the longest and top most string in the middle set.  This is a G note.

You can play the guitar with your mouse, but it is kinda difficult.  To use your keyboard, use the following Google Guitar codes...

Keyboard Letter = Musical Note
A = G
S = A
D = B
F = C
G = D
H = E
J = F#
K = G
L = A
; = B

So you get a full octave plus notes 2 and 3 (A and B) on the high register.  Just enough to play the National Anthem!

Here is my composition showing how to play a scale on the Google guitar.

... 

got some time to play.  Here's some tunes...

Mary Had a Little Lamb - http://goo.gl/doodle/FzZK

National Anthem - http://goo.gl/doodle/Ix77

My G-Comp 1 - http://goo.gl/doodle/9xi9

My G-Comp 2 - http://goo.gl/doodle/N0itG

Coldplay Trouble - http://goo.gl/doodle/3NT7E

Blues Riff - http://goo.gl/doodle/dvhqL

My Bonnie Lies Over The Ocean - http://goo.gl/doodle/hjNtv

Tags:

 

View Request/Response in .NET Web Services

I recently ran into some issues with a third-party web service, and needed view the request xml being sent down the wire.  The options came down to using a sniffer to watch HTTP traffic sent from my application or implement a SoapExtension to intercept the different phases of the SOAP request.

My first approach was to use a traffic sniffing tool such as Fiddler.  Unfortunately, using Fiddler with SSL Secured Web Services is tricky at best.  The process involves a number of changes to Fiddler's configuration.  I decided to take another route, but if this is something you are interested in, there is a great in-depth article by Rick Strahl at WestWind Technologies on how to configure Fiddler for HTTP traffic monitoring.

After playing with Fiddler for a while, I decided to take a different approach and use the SoapExtension base class to create a custom extension to intercept request and response data streams.  Doing this allows me to do what ever I want with the data.  For this purpose, I simply logged the messages to xml files on my local machine, but I could also see using the extension to log xml data to a database.

The MSDN documentation on SoapExtensions shows a decent example, but the best example I found was an article on MSDN Magazine.  It includes sample code, and also shows how to use the extension on both the client and the server.  On the server you implement the extension using a custom attribute applied your Xml Service Method.  On the client, you can add your custom extension in your web.config or app.config section in system.web\soapExtensionTypes.

 

 

Tags: ,