Creating an extension module for .NET URL Rewriter and Reverse Proxy

Wow that is a long title. Recently I have been looking for quick posts that I can put out each day to keep my blog relevant and also so I don’t feel like I am slacking off too much. Today I want to post about a little known feature in my .NET URL Rewriter and Reverse Proxy (aka. Managed Fusion URL Rewriter) that I have developed in my spare time, mostly out of necessity for this blog and other projects I have worked on. Here is a quick run through of what it does. ...

December 9, 2008 · 5 min · 1040 words · Nick Berardi

How NOT To Optimize LINQ Statements

About a month ago I was experimenting with different ways to optimize my LINQ queries against the IdeaPipe database, in order to improve the read times. I wanted to improve the read times because our new Facebook Application was being launched and I anticipated an increase in our traffic to the server, which is used to host IdeaPipe and the Facebook Application component. Whenever I am trying to optimize SQL queries I fire up SQL Server Profiler and take a look at how the queries are performing. This helps me identify queries that are taking a longer time to execute and probably need to be looked at or re-thought. One of the queries that I identified as needing improvement was the following LINQ query: ...

September 24, 2008 · 4 min · 787 words · Nick Berardi

MVC CAPTCHA for Preview Release 3

Since my last release of the MVC toolkit some major changes have taken place in the MVC Framework. I am going to do a quick run through of how they changed the MVC CAPTCHA for the better. Originally in MVC Preview Release 1 for the MVC CAPTCHA many of you remember that the indicator for a valid CAPTCHA was passed through the parameters of the action method like so: [ControllerAction] [CaptchaValidation("captcha")] public void Register(bool captchaValid, string otherParameters) { // do stuff } However when Preview Release 2 came out the ability to pass the parameter through the action method was broken. So I had to create a hack around this: ...

June 24, 2008 · 3 min · 575 words · Nick Berardi

MVC + Facebook == Wonderful Development Platform

Just recently I started experimenting with the ASP.NET MVC Framework and the Facebook Development Platform, it has been a very bumpy road, but I have ironed out some major issues that I would like to share with you today. I will start with a little history of what I am trying to do. For about a month and a half I have had one of my IdeaPipe interns, Dimitry, experimenting with creating a FBML (Facebook Meta Language) Application with MVC. MVC is an ideal platform for FBML because with MVC you have total control over your markup which is needed to have a lean FBML application. I am not going to go in to the differences of developing an FBML vs IFrame Facebook Application, because that information is easily found with a Google Search. What I am going to talk about is the hurdles I overcame and the custom software I had to develop to get MVC working smoothly with Facebook. ...

June 6, 2008 · 4 min · 653 words · Nick Berardi

Give Your ASP.NET Applications Velocity

Scaling ASP.NET Application just got easier with a new technology that Microsoft has just released that they have dubbed codename “Velocity”. This product is still in the early stages of development, but it is meant as a direct competitor against memcached. If you are not familiar with memcached, here is how it is described in Wikipedia: memcached (pronunciation: mem-cache-dee) is a general-purpose distributed memory caching system that was originally developed by Danga Interactive for LiveJournal, but is now used by many other sites. It is often used to speed up dynamic database-driven websites by caching data and objects in memory to reduce the number of times the database must be read. Memcached is distributed under a permissive free software license. ...

June 5, 2008 · 3 min · 533 words · Nick Berardi

ASP.NET MVC Preview 3 Released

The ASP.NET MVC Team has released an refresh of MVC. To all those that are interested the new Preview Release is posted at: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=13792 The new release contains many new features over the 2nd Preview Release and the Interim Release from a month a half ago. In this post I am going to outline the features that are new from the Interim Release to Preview Release 3. Action Method and Result Changes As you remember from the previous release, you are now required to return an ActionResult. Many of the ActionResults were renamed to the following types: ...

May 27, 2008 · 4 min · 782 words · Nick Berardi

Microsoft Source Analysis Still Needs Work

Microsoft just released a tool called Microsoft Source Analysis for C#. Apparently it is a tool they use internally to make sure all their souce code looks the same and is easily readable by all those who use it. According to the blog post that announced this: Source Analysis comes with a set of default rules analyzers covering approximately 200 best practice rules. These rules are full compatible with the default layout settings in Visual Studio 2005 and Visual Studio 2008. Specifically, these rules cover the following, in no particular order: ...

May 23, 2008 · 3 min · 638 words · Nick Berardi

Interesting Extension Hack To Get Around NullReferenceException's

Today I came across an interesting extension pattern that I didn’t know how the runtime would react. Normally when you do something like the following: string s = null; Console.WriteLine(s.Trim()); // throws NullReferenceException You get a NullReferenceException meaning that you didn’t first check to see if the object was null before trying to call one of its methods. This is pretty common and results in patterns that usually look like this: ...

April 24, 2008 · 2 min · 313 words · Nick Berardi

Coder Journal's MVC Toolkit

Today I decided to release a toolkit that I have been building over the past couple of months. Most of the code in the toolkit is related to MVC. Here is a list of the features: ActionFilterAttribute’s HttpPostOnlyAttribute Only allows POST to be made against the action. CacheAttribute Sets the action’s response as cacheable. CompressAttribute Compresses the action’s response using GZip or Deflate encoding. ServiceAttribute Marks an action as able to provide the ViewData as JSON, XML, or JSONP. ServiceOnlyAttribute Marks an action as only able to provide the ViewData as JSON, XML, or JSONP, that means no HTML. ExceptionHandlerAttribute Handles any exceptions thrown from an action, and redirects it to another page, or another action. CaptchaAttribute I did a whole post on providing a CAPTCHA for your MVC action. AllowedHttpMethodsAttribute Only the HTTP methods entered in to this filter are allowed for your action. Available HTTP methods are OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, and CONNECT. ViewEngines’s ServiceViewEngine This view engine provides the serialization of the ViewData to JSON, XML, or JSONP. It is set when one of the following is requested from the ServiceAttribute above. Route’s LowercaseRoute I did a whole post on why I needed this in my toolkit. Mostly because of my obsessions to have all URL’s in lowercase. Method Extensions Redirect extends HttpResponse I have had a long standing discontent with the Redirect method of the ASP.NET. I have talked about good use of HTTP Status Codes before. There are at least 3 status codes that you want to consider before choosing a response status code of 302. Just to reiterate my post on the subject use 303 to redirect from a form POST, use 307 when you want to redirect to a page that is going to change with each request, use 301 if you want to permanently redirect one URL to another.I created the, Redirect, extension method on HttpResponse so that the status code could be set for the redirect. View Source: Coder Journal MVC Toolkit Source Download Binary: Coder Journal MVC Toolkit Binary ...

April 13, 2008 · 2 min · 358 words · Nick Berardi

Why is JSON Deserialization so Important to Developers?

Recently I have been working on a RESTful interface for a Web 2.0 project that I will be releasing very soon. And one of the self imposed requirements that I set out to achieve was to have the RESTful interface output the same structure JSON as XML. This way that any developer using the interface would feel comfortable using the JSON and XML interchangeably. But, I have been having a lot of trouble recently getting my JSON and XML to output the same structure when using the built in .NET methods. I have tried the following: ...

April 3, 2008 · 3 min · 542 words · Nick Berardi