WordPress – Replace default footer copyright info

By default WordPress adds copyright and theme acknowledgement details to the footer. This can be changed by updating the footer.php file.

1. Open the Editor from the Appearance menu.
2. Select the relevant theme and find footer.php under the templates section.
3. Scroll down and you should find a

section or something similar.
4. In this div you should see the footer text, update as necessary and click the Update File button.

Rename ASP.net cookie

You can adjust it in your web.config file, the default is ASPXAUTH:

   <authentication mode="Forms">
      <forms name=".CRM-Cookie" loginUrl="LoginPage.aspx" />

This is useful when running multiple applications from the same server under the same domain. 

ASP.net CheckBoxList validation

A custom validator can be used to validate a CheckBoxList control. However its crucial the correct attributes are passed. The most common mistake is using the ControlToValidate in CustomValidator. By using this you encounter the following:


Instead just use the OnServerValidate attribute to point to a validation method in the code behind. In this method create a reference to CheckBoxList control and run any validation required.

MVC Ajax Sys is undefined message

I spent an entire day trying to figure out why my Ajax.Begin form helper was failing to update the target div container. By chance I noticed the Sys is undefined message flash past in the Chrome console window. I’ve seen this before with Ajax enabled websites and it usually points to the project not being configured to use Ajax correctly. The jquery.unobtrusive-ajax package has been installed through NuGET correctly but it hadn’t set the configuration correctly.

Make sure the jquery.unobtrusive-ajax.js file is loaded after jquery and <add key=”UnobtrusiveJavaScriptEnabled” value=”true” /> in included in the web.confg <appSettings> section.

Visual Studio Creates an unwanted _ViewStart.cshtml

Many people have noticed Visual Studio sometimes creates an unwanted _ViewStart.cshtml in MVC projects. This happens when a Views is created manually from the Visual Studio right click menu rather than a controller.

The _ViewStart.cshtml file can cause all sorts of unwanted issues, especially when used in conjunction with third party systems such as Sitecore (can cause infinite looping when rendering a view).

To prevent this file being created make sure Use a layout page is unticked or if the view will be used as a partial view tick Create as a partial view.

MVC model binding with helpers

It is possible to bind your HTML controls to a model without the use of helpers such as @Html.TestboxFor()

Take this controller

public class MyControllerController : Controller
     public ActionResult Submit()
         return View(new MyViewModel());

     public ActionResult Submit(MyViewModel model)
            // model should be not null, with properties properly initialized from form values
            return View(model);

and model

public class MyNestedViewModel
    public string AnotherProperty { get; set; }

public class MyViewModel
    public MyViewModel()
         Nested = new MyNestedViewModel();

    public string SomeProperty { get; set; }

    public MyNestedViewModel Nested  { get; set; }

The values can be bound to the model using pure HTML.

<form method="POST" action="MyController/Submit">
    <div><label>Some property</label><input type="text" name="SomeProperty" /></div>
    <div><label>Another property</label><input type="text" name="Nested.AnotherProperty" /></div>
    <button type="submit">Submit</button>

C# Virtual Methods

A vertical method can be redefined in derived (class which inherit from this) classes. A virtual method has an implementation in both the base and derived class. These methods are used when the base class provides the required functionality most of the time, but may need changing by a derived class on occasion. A virtual method can be redefined by the derived class using the override keyword with the same method name. Methods which are not defined as virtual cannot be overriden in a derived class and must use the functionallity provided in the base class.

Example – Both the Rectangle and Circle classes inherit from the Shape class. However has the area of a circle is calculated differently to a rectangle, the circle class overrides to Area method. As the Colour method isn’t virtual both derived classes have to use the same method so in this case both will be red.

class Shape
	public string Colour()
		return "Red";
	public virtual double Area(double width, double height)
		return width*length;

class Rectangle : Shape
	public Rectangle()
		string colour = Colour();
		double width = Area(10.5,15);
class Circle : Shape
	public Circle()
		string colour = Colour();
		double width = Area(15);
	public override double Area(double radius)
		return 3.141*raduis*2;

What is dependency injection 

A simple definition is:

Dependency Injection is where components are given their dependencies through their constructors, methods, or directly into fields.

For example a class constructor creates an instance of an object. This class is now dependant on that object. If however this object is passed into the constructor this dependancy is decoupled.

For dependancy injection to work correctly each class requires an interface. This will ensure if the object is switched it will still present the same methods, it doesn’t however need to know what these methods do.

Unit testing as one of the main uses for dependancy injection. It allows objects which perform complex data processing tasks to be replaced with an object which provides mock data for testing. The class being tested doesn’t care how this data is created as long as it’s presented in the same format.

Another example is an object provided SQL database access methods. Using dependancy injection we can switch this to another object with MySQL access methods. As long as both objects expose the same methods the objects using them won’t care which one it is.