Contents tagged with asp.net

  • 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 http://asp.net/mvc/mvc4.  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

  • 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

  • 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

  • DevConnections Session Feedback

    Last week I just got back my summaries of attendee feedback for my three talks at DevConnections in Orlando in April (yes, they're not quite as efficient as TechEd).  I blogged about them and posted the slides and demos 2 months ago, but I'm finding it useful to also blog about the comments and feedback that I received on them, as a means of helping me to improve my future talks and, I hope, as a way of showing that I actually do read and care about what attendees say on the evals. For my talk on What's New in ASP.NET 3.5 there were 59 evals turned in.  The overall evaluation for the talk was a 3.39 which was slightly below the average of 3.46.  An astonishing 50% of the evals … more

  • Black Belt ASP.NET Performance Talk

    I gave my Tech Ed presentation, ASP.NET Black Belt Performance Techniques, yesterday afternoon.  The talk was well-attended, with about 300 372in the audience.  I gave the talk last month in Cleveland and it was very well-received.  I promised attendees the slides and demos would be available on Tech Ed's CommNet, and right now the slides are but I'm having trouble getting the demos uploaded so I'm also posting everything here: Download DemosDownload PPT I wasn't terribly happy with my performance with this talk, and the overall evaluation average for it was 7.84, which is pretty respectable (based on evaluations from 1 to 9 in a few categories) - the best talks at the show … more

  • Black Belt ASP.NET Performance Techniques

    Last night I presented at the Cleveland .NET SIG on Black Belt ASP.NET Performance Techniques, which is a talk I'll be giving in a few weeks at Tech:Ed Developers in Orlando.  I was asked a couple of weeks ago if I could give a talk in May and I decided to do it so I could practice for TechEd.  Since this is a new talk for me (though its material is familiar), I had to put together a new set of demos, and having this user group meeting was a good way to keep me from procrastinating until June to get my demos working.  The talk covers performance metrics, load testing, and some performance tips (and shows their relative impact on a realistic application using load … more

  • Speaking in Cleveland May 13th

    I'll be speaking at the Cleveland .NET SIG tomorrow night.  The topic is Black Belt Performance Tips for ASP.NET, which will be a dry run for a session by that same name I'll be giving next month at Tech:Ed Developers in Orlando.  Some of the primary areas covered will be advanced caching techniques and asynchronous programming techniques (for ASP.NET).  The user group meets at the Microsoft office in Independence, Ohio from 5:45pm to 7:30pm and usually is pretty crowded. more