Monday, 28 October 2013

Microsoft Certified Solutions Developer: Web Applications


I would like to say that today I passed my next exam 70-492, Upgrade your MCPD: Web Developer 4 to MCSD: Web Applications.

Over the next few months I will try to blog more, now that I've stopped my studying for the time being.

Friday, 21 June 2013

Microsoft Specialist in Programming in HTML5 with JavaScript and CSS3


For my 100th post, I would like to say that today I passed the Microsoft Specialist exam 70-480, Programming in HTML5 with JavaScript and CSS3.

Saturday, 6 April 2013

MCPD Web Developer 4


Yesterday I successfully passed the upgrade MCPD exam 70-523. Got a great pass mark, so glad that all the studying paid off.

Thursday, 28 March 2013

SSIS on 64bit Dev machine

You have an "Execute SQL Task" to return a "Full result set" but when executing you get the following error.

[Execute SQL Task] Error: Executing the query "SELECT * FROM Table" failed with the following error: "Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Are you running on Windows 7 64bit? A possible fix if you are is to set the run time to 32 bit. You can do this by:
  1. Go to Project Properties
  2. Configuration Properties -> Debugging
  3. Set Run64BitRuntime False

Wednesday, 24 October 2012

Visual Studio 2010 not opening CSS files

Recently I have had a problem where Visual Studio 2010 wouldn't open any CSS files. I can't say for sure if this started happening just after I installed SP1 as I don't tend to edit many CSS files.

The solution I found was to install the following extension.
Extension Manager -> Online Gallery
Search for: "Web Standards Update for Microsoft Visual Studio 2010 SP1"

This information I found on the social MSDN site here.

Thursday, 31 May 2012

Unit testing MVC routes

If you are using the MVC Routing engine, you can test your routes to ensure that they work as expected.

To test the default route:

[Test]
routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home",
          action = "Index",
          id = UrlParameter.Optional }
);

The example test is:

[Test]
public void DefaultRouteTest()
{
    var routes = new RouteCollection();
    var application = new Application();
    application.RegisterRoutes(routes);

    var context = new Mock<httpcontextbase>();
    context.Setup(p => p.Request.AppRelativeCurrentExecutionFilePath)
                                   .Returns("~/");
    var routeData = routes.GetRouteData(context.Object);

    Assert.AreEqual(((Route)routeData.Route).Url, 
                    "{controller}/{action}/{id}");
    Assert.AreEqual("Home", routeData.Values["controller"]);
    Assert.AreEqual("Index", routeData.Values["action"]);
}

This came from an original post by Scott Gu, that we had to change slightly. http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

The original code was causing the first parameter to drop the first character. i.e. For the default route, the controller was return 'ome' instead of 'home'.

Wednesday, 11 April 2012

Profile not available in Web Application

Using the Web Application project, you are unable to use the intellisense on the Profile class. A workaround has been provided by Joe Wrobel in a post build task.
This post build task is called Web Profile Builder and can be download here.
The simple approach:
  1. Install the package.
  2. Add the following to your .csproj file
    <Import Project="$(MSBuildExtensionsPath)\WebProfileBuilder\WebProfileBuilder.targets" />
  3. Build project
Joe has a more details in his post on how to use the build task.

Datatables update function shows an Alert Box

When using the jQuery Datatable plugin and jeditable to allow tables to be editable, calling the update function via sUpdateUrl shows an alert box on it's return.
To suppress the alert box, return the same value that was originally passed in.
C# MVC Example:
$('#myDataTable').dataTable().makeEditable({
    sUpdateURL: "/Home/UpdateData"
})

public class HomeController : Controller
{
    public string UpdateData(int id, string value,
                             int? rowId, int? columnPosition,
                             int? columnId, string columnName)
    {
        //Add code to update cell
        return value;
    }
}
Code borrowed from http://code.google.com/p/jquery-datatables-editable/wiki/EditCell

Tuesday, 6 March 2012

Checkbox validation with the MVC data annotations

I've been using MVC3 for a new site and require a check box to be true before continuing. e.g. "Accept T & Cs".

The data annotation have the [Required] attribute for other field types, but this is ignored for check boxes.

You can create your own custom validators. Below is an example for a single check box to ensure it is true.

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class MustBeTrueAttribute : ValidationAttribute
{
      public override bool IsValid(object value)
      {
            return value != null && value is bool && (bool)value;
      }
}

You can then add the attribute to your MVC component model

[Display(Name = "I accept the terms and conditions")]
[MustBeTrue(ErrorMessage = "Please accept terms and conditions before continuing")]
public bool AcceptTerms { get; set; }

This solution was discovered on StackOverflow

Thursday, 19 January 2012

WCF Error - This collection already contains an address with scheme http.

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
I've found two solutions to this error depending on which version of the .NET framework you are using. You need to update the web.config with the following:

.NET 4.0

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

.NET 2.0 - 3.5

<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://www.yourdomain.com"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>