Archives

Archives / 2010 / December
  • Favor Privileges over Role Checks

    A very common practice in web applications, especially those written using the ASP.NET built-in Role provider (circa ASP.NET 2.0 / 2005), is to perform role checks throughout the code to determine whether a user should have access to a particular page or control or command.  For instance, you might see something like this:

    if (CurrentUser.IsInRole(Roles.Administrators) ||

    CurrentUser.IsInRole(Roles.SalesAgents))

    {

    SomeSpecialControl.Visible = true;

    }

    The problems with the maintainability of this approach become apparent after a short while.  For one, any buttons or other controls on the SomeSpecialControl above that post back to the page should … more

  • How Can I View MSMQ Messages and Queues?

    I’m working with NServiceBus to send messages to and from different parts of my application.  NServiceBus is a mature tool that sits on top of MSMQ and provides a great developer experience for working with a number of different scenarios.  One thing that’s challenging when working with queues is figuring out where a message went when it doesn’t show up at the other end of the message bus.  Where did things go wrong?  How can I see the messages in the queue for MSMQ?  Is the queue set up and working?

    It turns out that there is built-in support for viewing details of MSMQ baked into the MMC snap-in, though it’s not immediately obvious where to … more

  • Get the Batch File’s Path in a Batch File

    I’m a huge fan of build automation, and all of my dev projects include scripts to build, test, deploy, run etc.  Sometimes these use PowerShell and quite often they use MSBuild (or occasionally NAnt) but batch files remain a very simple and powerful way to take care of automation business.  Today I’m trying to wrap up my use of NServiceBus on a project that’s going live with some CQRS goodness, and I want a simple way to kick off the host process while I’m doing development so I don’t have to go to the trouble of running the thing from Visual Studio.  Anyway, to make a long story short, I needed to refer to the current path of the batch file within the batch file itself.  … more

  • Singleton Pattern

    I recently published an article on Alternatives to the Singleton Design Pattern on AspAlliance.com.  If you’re a fan of the Singleton pattern, I would encourage you to have a read and feel free to comment (here or there) if you agree or disagree with my position.  You can also learn more about the Singleton in the Patterns Library at Pluralsight.  Finally, if you haven’t read it, I definitely recommend checking out Jon Skeet’s coverage of the Singleton, as it provides several alternative implementations and demonstrates several weaknesses of the naïve implementation of the pattern. more