Contents tagged with

  • Find Debug Assemblies using Glimpse

    A new feature in Glimpse.AspNet 1.9.2 will display whether each assembly in your web site’s bin folder was compiled in Debug or Release mode. At development time, Debug mode is fine, but you want to avoid shipping Debug assemblies to production since there are performance costs associated with these assemblies.  You can determine for yourself whether a given assembly was compiled in debug mode using this code, which also links to the performance issues. Under the Environment tab in Glimpse, you can scroll down to view the Application Assemblies section. The new column, Build Mode, shows for each assembly how it was compiled.  In your production deployments, you want to make sure … more

  • DogFoodCon Session on DDD with ASP.NET MVC

    Yesterday I presented at DogFoodCon, giving a slightly modified version of a talk I gave a week earlier at FalafelCON in San Francisco.  The session provides those with little knowledge of Domain-Driven Design with a rapid overview of some key concepts and patterns used in DDD, and wraps up with a brief demo of a simple Guestbook application that begins as a monolithic everything-in-the-controller MVC application but is improved using some DDD-based techniques.  The slides are available on Slideshare and embedded here: Add Some DDD to Your ASP.NET MVC, OK? from Steven Smith Both times I gave the talk, I ran out of time to show everything I wanted in the demo (sorry, it’s a big … more

  • Resolving Dependencies in ASP.NET MVC 5 with StructureMap

    In a previous post I showed how to use StructureMap with ASP.NET MVC 3.  It’s been a couple of years, so I figured it was time to update that article with the steps for getting StructureMap working in ASP.NET MVC 5.  If you’re interested in learning more about how to develop applications in a loosely coupled fashion, I highly recommend my course on SOLID Principles of Object Oriented Design to learn more (in particular, the Dependency Inversion Principle). StructureMap is my preferred IOC container / dependency injection tool for .NET applications.  It’s free, performs very well, and has a number of very useful features that make it very productive to work with.  One … more

  • Wiring Up TimeAgo and ASPNET MVC

    Imagine you want to display something on a page so that instead of raw dates, the user is shown something more relative to the current time.  You’ve probably seen this in some of the applications you use.  “Last Updated: A moment ago” or “about an hour ago”.  There are a variety of ways you can implement this, and it’s been done in many different languages.  In my case, which is an ASP.NET MVC C# application, I considered doing it on the server and simply passing the result as a string to the view for display.  However, in searching for the best way to do this, I stumbled upon the Timeago plugin for jQuery. One of the key benefits of this plugin is that, unlike … more

  • How To Contribute to ASPNET Yourself

    Recently I upgraded the Stir Trek conference site’s web code from ASP.NET MVC 2 to 4.  When I did, I ran into an issue where the [OutputCache] attribute’s behavior changed for RenderAction code.  Specifically, if you had code like this: [OutputCache(CacheProfile="Default")]public ActionResult SponsorList(){ var context = new DataContext(); var sponsors = context.Sponsors.GetAll().Where(s => s.Type.Amount > 0).OrderByDescending(x => x.Type.Amount).ToList();   return this.View(sponsors);} it would stop working.  You would get an error message like this: Now, this error will make no sense to you if, like me, it used to work just fine in MVC 2, and you … more

  • Getting StructureMap to Work with MVC4 RC and Web API

    At the moment (18 July 2012) if you install the NuGet package structuremap.MVC4, it will not compile due to breaking changes in the ASP.NET MVC4 RC distribution.  You have to jump through some extra hoops to get this working.  Here are two posts that help: Configuring MVC4 with StructureMap Using the Web API Dependency Resolver However, even with both of these getting things working wasn’t quite as easy as I would have liked.  Here are two full files with namespaces showing what I used to get things working (Gist 3135943).  I assume the NuGet package will be updated to be correct once MVC4 ships. more

  • Beyond Role Based Authorization in ASPNET MVC

    A fairly frequent requirement in applications is to check for authorization to perform an action.  At the most basic level, this might just involve seeing if the user is authenticated (at all) or checking a flag to see if they are an Admin.  However, more complex requirements frequently include a variety of roles, and it’s quite common for the notion of ownership to be involved as well, with some actions being allowed if you own the item being worked on, and otherwise not.  I’ve written about using the notion of Privileges over Role Checks for this exact purpose in the past, as a way to ensure the logic of such decisions is properly encapsulated so that you can follow the … more

  • Getting Started with Single Page Applications in ASP.NET

    One of the new features in ASP.NET MVC 4 (Beta) is a new project template for Single Page Applications (SPA).  You can download the latest version of MVC4 from  Once you have that installed, get started by creating a new ASP.NET MVC 4 project: You’ll immediately be asked another question about exactly what kind of project you’re looking to create.  This is only asked on project creation, but it’s possible in the future you’ll be able to mix and match these kinds of templates and the resources they provide in a more ad hoc manner, after projects are created, in the future.  For now, though, to check out Single Page Applications, choose that … more

  • Fixing Floating Rectangles in ASP.NET StackedBar Chart

    In working on a client’s reporting system, I ran across some StackedBar charts that were using the System.Web.DataVisualization.Chart control that were having some problems.  The biggest one was that the rendered bars had gaps and floating rectangles in it.  This turned out to take about an hour to solve, using my best Google-fu, so I’m posting my solution and notes here, in case I run into it again and to save some other poor soul an hour’s time. The Problem Here’s what the chart looked like, originally.  I’ll spare you the original code, as it was a total rat’s nest, but I was able to dramatically simplify it before proceeding to fix the actual issue.  A bit of … more

  • How Do I Use StructureMap with ASP.NET MVC 3

    Update: If you want to use StructureMap with ASP.NET MVC 5, I have a walkthrough on this now as well.

    As I write this, the best resource for official documentation on ASP.NET MVC 3 is of course MSDN.  You can also learn more about ASP.NET MVC 3 here.  However, neither of those mention how to properly set up an IOC Container (like StructureMap) with ASP.NET MVC 3.  After some searching, I was able to get things working using the RTM version of ASP.NET MVC 3.  Here’s what I had to do.

    Step One – Global.asax – Application_Start()

    First, you need to wire things up when your application starts.  You can put all of your container registration stuff … more

  • 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) ||



    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

  • Speaking in Toledo Tonight

    I'll be presenting at the Northwest Ohio .NET User Group this evening at 6pm.  The talk will be a slightly modified version of my Black Belt ASP.NET Performance talk that I gave earlier this month at Tech Ed in Orlando.  According to their web site, the user group will also be giving away a Zune to one of the attendees of tonight's meeting (and I have a book and some shirts, too...), so if nothing else, you can come for the free stuff. The main topics covered in this talk are performance testing with load testing tools, caching, and asynchronous programming. more