Just sharing some of my inconsequential lunch conversations with you... RSS  

Friday, November 21, 2008

The easiest HttpHandler ever!

Not that HttpHandler is hard to create, but it can get quite intrusive mainly because of configuration issues.

The ashx extension simplifies all this process. Here's all you've got to do:

namespace MyProject
{
using System;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for FederationLogin
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class FederationLogin : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
try
{
//
// set content type to jpeg
// TODO: consider changing to smaller footprint png version

context.Response.ContentType = "image/jpeg";

// dump image according to credential presence
context.Response.WriteFile(Credentials != null ? "SignedInOnFederation.jpg" : "NotSignedInOnFederation.jpg");
}

catch
{
//
// Oops, something went wrong: opt for a non-intrusive (but non-assertive)
// KISS approach: just assume no federation ticket was issued.
// Please note: no log is being issued.

context.Response.ContentType = "image/jpeg";
context.Response.WriteFile("NotSignedInOnFederation.jpg");
}
}

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


This is a simple SignIn on federation button. But more about it later, I'm still on an NDA on this one.

No comments:

Development Catharsis :: Copyright 2006 Mário Romano