Sunday, May 20, 2012

MvcBundleConfig NuGet Package

MvcBundleConfig is now available on NuGet!

MvcBundleConfig is a very simple project that adds configuration and debugging features to MVC 4's bundling framework. Once you create a new MVC4 web application and install the MvcBundleConfig NuGet Package, then you need only update our layout to use the new bundle extension methods, and you are ready to go!

Please note that the System.Web.Optimization NuGet package is still in beta, and thus that dependency is not included in the current version of the NuGet package. However, if you have created a new MVC4 project then that assembly should already be included.

Sample Installation Steps

  1. Create a new ASP.NET MVC 4 Project
  2. Select Manage NuGet Packages
  3. Search for and install MvcBundleConfig
  4. Update the Layout
kick it on DotNetKicks.com

Enjoy,
Tom

Friday, May 4, 2012

Configuring WebClient Timeout and ConnectionLimit

Simplicity is nice, but not when it comes at the expense off accomplishing your goal.

Recently I have been using System.Net.WebClient to access some REST APIs. It is great how simple the WebClient class is to use, but unfortunately it does not natively support configuring it's timeout or connection limit. In fact, before I knew that the default connection limit was preventing me from making more than two concurrent requests at a time, it was actually causing me some serious issues while doing performance testing.

Good news, both of these issues are very easy to fix by simply extending the WebClient class.

Sample Class

public class ConfigurableWebClient : WebClient
{
    public int? Timeout { get; set; }
    public int? ConnectionLimit { get; set; }
        
    protected override WebRequest GetWebRequest(Uri address)
    {
        var baseRequest = base.GetWebRequest(address);
        var webRequest = baseRequest as HttpWebRequest;
        if (webRequest == null)
            return baseRequest;
 
        if (Timeout.HasValue)
            webRequest.Timeout = Timeout.Value;
 
        if (ConnectionLimit.HasValue)
            webRequest.ServicePoint.ConnectionLimit = ConnectionLimit.Value;
 
        return webRequest;
    }
}
kick it on DotNetKicks.com

Enjoy,
Tom

Real Time Web Analytics