Could not load all ISAPI filters for site ###. Therefore site startup aborted.

Whilst setting up a site on a 64bit server running IIS7.5, I was stumped with this error in the event log for a few hours “Could not load all ISAPI filters for site ###.  Therefore site startup aborted.” A quick search of Google resulted in a number of fixes, none of which helped.

My colleague and I eventually discovered that the error was caused by a setting the advanced settings section of the application pool. To fix this yourself complete the following steps:

  • Open IIS and navigate to the application pool in question.
  • Right click and select Advanced Settings…
  • In the (General) section locate “Enable 32-Bit Applications” and set this value to True
  • Click OK
  • Restart the web site

Presenting designs, concepts and projects to clients with Prezi

A couple of years ago I came across Prezi an interesting web application that allowed you to create online presentations to collaborate and share them with others. Recently I have revisited Prezi to see what’s new and I’m pretty impressed. The app is now a whole lot easier to use and has a lot of great innovative features.

About Prezi

Extract from the Prezi website:

“Prezi is a cloud-based presentation software that opens up a new world between whiteboards and slides. The zoomable canvas makes it fun to explore ideas and the connections between them. The result: visually captivating presentations that lead your audience down a path of discovery.”

The developers at Prezi are constantly designing new features to make the experience better and introduce new features. I think this is a fantastic application to use for presenting web designs, technical concepts and project updates to your clients. If you don’t mind your presentations being public then app is free to use. If you would prefer to keep your presentations private then Prezi offer 2 packages, Enjoy at $59 per year for 500mb or Pro at $159 per year for 2gb and an a desktop app to create your presentations. Students and teachers can have the Enjoy package for free and the Pro package for $59 per year.

Example Presentation

Recently I was tasked with educating a client on the current state of mobile web technology and what options were available for publishing her app. Prezi came in very handy, it allowed me to formulate my research and present my findings in a simple and easy to use web interface. Prezi has an awesome feature called Prezi Meeting that allows you to invite a user to view your presentation and have remote control of the what the user sees on their screen. This feature is great for presenting a software idea, web site design compositions and concepts over the phone.

Here is a link to my presentation on mobile technologies for 2012
(You are free to create a copy and modify this for your own use)

Switching to C Sharp from VB.NET

Here is a collection of handy snippets for VB developers who may be in the process of transitioning to C#.

Comments

Single line

//Comment

Multi-line comments

/* This section
is commented */

XML Comments

/// My XML Comment

C# Data Types

  • byte
  • sbyte
  • int
  • uint
  • short
  • ushort
  • long
  • ulong
  • float
  • double
  • decimal
  • bool
  • char
  • string
  • object

C# Variable Declaration

public | protected internal | protected | internal | private type variable-name

Example

private string str_MyVar = "My Value";

C# Arrays

Single Dimension

<type>[] <name> = new <type>[ArraySize];

Example

string[] str_Array = new string[2];

Multi-dimensional

<type>[,] <name> = new <type>[ArraySize,ArraySize];

Example

string[,] str_MultiArray = new string[5,4];

ArrayList

ArrayList resizes dynamically. As elements are added, it grows in capacity to accommodate them. It stores a collection of elements of type object; therefore casting is necessary. You also need to reference System.Collections.

Example

ArrayList list = new ArrayList();
list.Add("One");
list.Add("Two");
list.Add("Three");

Initialize Array

<type>[] <name> = new <type>[ArraySize] {<value1>, <value2>, … , <valueN>};

Example

int[] int_MyValues = { 1, 2, 3, 4, 5 };

Change Size of Array

<type>[] <name> = new <type>[ArraySize];

Example

Array.Resize(ref int_MyValues, 10);

Operators

Arithmetic

+ (Addition), – (Subtraction), * (Multiplication), / (Division), % (Modulus)

String Manipulation

  • Concatenation: str_WelcomeText = “My name is ” + “Fred Blogs”;
  • .Substring(<start>,[<length>])
  • .Trim() <trims from beginning & end of string>
  • .TrimEnd([<char array>])
  • .TrimStart([char array])
  • .ToLower() <to lower case>
  • .ToUpper() <to upper case>
  • .Replace(<find>,<replace>)
  • .Equals(<expression>) <6 available overloads>
  • .Contains(<string>)
  • .Join(<seperator>,<value>,[<count>])
  • .Compare(<string1>,<string2>,[<ignore case>]) <7 overloads available>
  • .Copy(<string>)
  • \’ – single quote, needed for character literals
  • \” – double quote, needed for string literals
  • \\ – backslash
  • \0 – Unicode character 0
  • \a – Alert (character 7)
  • \b – Backspace (character 8)
  • \f – Form feed (character 12)
  • \n – New line (character 10)
  • \r – Carriage return (character 13)
  • \t – Horizontal tab (character 9)
  • \v – Vertical quote (character 11)
  • \uxxxx – Unicode escape sequence for character with hex value xxxx
  • \xn[n][n][n] – Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
  • \Uxxxxxxxx – Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

String Escape Characters

Assignment

  • = (Equals)
  • += (Addition)
  • -= (Subtraction)
  • *= (Multiplication)
  • /= (Division)
  • %= (Modulus)
  • &= (And)
  • |= (OR)
  • ^= (Exclusive OR)
  • >>= (Right Shift)
  • <<= (Left Shift)
  • == (Equal To)
  • ! = (Not Equal To)
  • < (Less Than)
  • > (Greater Than)
  • <= (Less Than or Equal To)
  • >= (Greater Than or Equal To)
  • is
  • as

Comparison

if (person is Employee)
{
   // Do employee stuff
}
else if (person is Customer)
{
   // Do customer stuff
}

Logical

  • & (And)
  • | (Or)
  • ^ (Xor)
  • && (AndAlso)
  • || (OrElse)

Error Handling

try
{
//<statements that may cause an error>;
}
catch(Exception ex)
{
//<statements to use when an error occurs>;
}
finally
{
//<statements to use no matter what happens>
}

Example (from MSDN)

try
{
   myCommand.Connection.Open();
}
// Catch the exception as e and pass it to the ShowErrors routine.
catch (SqlCeException e)
{
   ShowErrors(e);
}

// Error handling routine that generates an error message
public static void ShowErrors(SqlCeException e)
{
   SqlCeErrorCollection errorCollection = e.Errors;

   StringBuilder bld = new StringBuilder();

   Exception inner = e.InnerException;

   if (null != inner)
   {
      MessageBox.Show("Inner Exception: " + inner.ToString());
   }

   // Enumerate the errors to a message box.
   foreach (SqlCeError err in errorCollection)
   {
      bld.Append("\n Error Code: " + err.HResult.ToString("X"));
      bld.Append("\n Message   : " + err.Message);
      bld.Append("\n Minor Err.: " + err.NativeError);
      bld.Append("\n Source    : " + err.Source);

      // Enumerate each numeric parameter for the error.
      foreach (int numPar in err.NumericErrorParameters)
      {
         if (0 != numPar) bld.Append("\n Num. Par. : " + numPar);
      }

      // Enumerate each string parameter for the error.
      foreach (string errPar in err.ErrorParameters)
      {
         if (String.Empty != errPar) bld.Append("\n Err. Par. : " + errPar);
      }

      MessageBox.Show(bld.ToString());
      bld.Remove(0, bld.Length);
   }      
}

Conditional Branching

If Else

if(expression)
{
   <statement 1>;
}
else
{
   <statement 2>;
}

C# version of IIF()

variable == ?true:false;

For Loop

for(statement)
{
   <statement>;
}

For Each Loop

foreach(<variable> In <object>)
{
   <statements>;

   [break];
   [continue];
}

While Loop

while(<expression>)
{
   <statement>;
}

Do-While Loop

do
{
   <statement>;
} while <expression>;

Select Case Statement

switch(<expression>)
{
   case <literal or type>:
      <statement>;
      <break>;
   case <literal or type>:
      <statement>;
      <break>;
   default:
      <statement>;
      <break>;
}

Else If

if (Condition_1)
{
   // Statement_1;
}
else if (Condition_2)
{
   // Statement_2;
}
else
{
   // Statement_n;
}

Functions & Sub Routines

Function Structure

<private, public, protected, internal> [static] <ReturnType> <Function_Name>;([Parameters])
{
   //body of the function;
   return <ReturnType>;
}

Sub Routine Structure

<private, public, protected, internal> void  <method_name>([Parameters])
{
   //body of the procedure;
}

Control Functions

void MyButton_Click (Object sender, EventArgs e)
{
   // When the button is clicked do stuff
}

<asp:Button id="MyButton" Text="Click Me" OnClick="MyButton_Click" 
runat="server" />

Class Structure

public class <Class_Name>
{
   //body of class
}

Base Class Idea
http://www.4guysfromrolla.com/articles/041305-1.aspx

public class MyBaseClass : System.Web.UI.Page
{
   protected override void OnLoad(EventArgs e)
   {
      // ... add custom logic here ...
      // Be sure to call the base class's OnLoad method!
      base.OnLoad(e);
   }
}

public class WebForm1 : MyBaseClass
{
   private void Page_Load(object sender, System.EventArgs e)
   {
      // Put user code to initialize the page here
   }
   ...
}

Good Example of Inheritance

http://www.4guysfromrolla.com/webtech/022001-1.shtml

General Items

Getting Item from AppSettings

Str_AppSettingValue = ConfigurationManager.AppSettings["app setting name"];

Getting current date and time as a string

Str_DateTimeExample = DateTime.Now.ToString("yyyy-MM-dd HH:mm tt");

Format Operators

  • d – Numeric day of the month without a leading zero.
  • dd – Numeric day of the month with a leading zero.
  • ddd – Abbreviated name of the day of the week.
  • dddd – Full name of the day of the week.
  • f,ff,fff,ffff,fffff,ffffff,fffffff –
  • Fraction of a second. The more Fs the higher the precision.
  • h – 12 Hour clock, no leading zero.
  • hh – 12 Hour clock with leading zero.
  • H – 24 Hour clock, no leading zero.
  • HH – 24 Hour clock with leading zero.
  • m – Minutes with no leading zero.
  • mm – Minutes with leading zero.
  • M – Numeric month with no leading zero.
  • MM – Numeric month with a leading zero.
  • MMM – Abbreviated name of month.
  • MMMM – Full month name.
  • s – Seconds with no leading zero.
  • ss – Seconds with leading zero.
  • t – AM/PM but only the first letter.
  • tt – AM/PM ( a.m. / p.m.)
  • y – Year with out century and leading zero.
  • yy – Year with out century, with leading zero.
  • yyyy – Year with century.
  • zz – Time zone off set with +/-.

Examples of best practice guidelines

http://www.codeproject.com/Articles/118853/Some-Best-Practices-for-C-Application-Development

Class Design Patterns (Gang of Four)
http://www.dofactory.com/Patterns/Patterns.aspx

ADO.NET Entity Framework – Querying the Data Model in Code

In my previous post we looked at how to bind ASP.NET controls directly to the Entity Framework (EF) data model using an EntityDataSource object. Whilst this technique offers a very simple and efficient way to databind your pages, it’s usefulness is limited and you may find that for complete control and flexibility you will better served by learning how to access the EF in code. You may find that databinding in code is more complex as there are many techniques and technologies to learn. However, if you are going to use the EF in a real world project you will soon discover handling the EF in your code behind pages, appears to be the most suitable and practical solution.

As there is too much to cover in one post, this article will try to provide an overview of the different ways you can query the data model to get subsets and single instances of data entities.

Overview of Querying Technology

Due to the way the Microsoft technologies have evolved, there are now many different ways to query the data in an Entity Data Model (EDM). I suggest you investigate each technology to find a technique that best suits your coding style and existing skill-set. The main ways to query an EDM are:

  • LINQ to Entities
  • Object Services and Entity SQL
  • LINQ Methods
  • Query Bulder Methods

LINQ to Entities

This method is my favourite way of querying the EDM. It’s pretty easy to read and whilst you are building your query, Visual Studio helps out by providing intellisense on the object field names.


DIM objModel As New PUBS_Context
Dim objTitles = From t In objModel.titles
Where t.pub_id = intPub_ID
Select New With
{t.title_id, t.pub_id, t.title1, t.type, t.price, t.ytd_sales, t.pubdate}

Object Services and Entity SQL

Here is the same query but using object services and Entity SQL with parameters.


DIM objModel As New PUBS_Context
Dim objParam As New System.Data.Objects.ObjectParameter("strPub_ID", strPub_ID)
Dim strSQL As String = "SELECT VALUE t FROM PUBS_Context.titles AS t WHERE t.pub_id = @strPub_ID"
Dim objTitles = New System.Data.Objects.ObjectQuery(Of title)(strSQL, objModel)
objTitles.Parameters.Add(objParam)

LINQ Methods

Again, here is the same titles query but this time using LINQ Methods.


DIM objModel As New PUBS_Context
Dim objTitles = objModel.titles _
.Where(Function(t) t.pub_id = strPub_ID) _
.OrderBy(Function(o) o.pubdate)

Query Bulder Methods

Finally, the same query but using Query Builder Methods.


DIM objModel As New PUBS_Context
Dim objTitles = objModel.titles _
.Where("it.pub_id = '" &amp; strPub_ID &amp; "'") _
.OrderBy("it.pubdate")

 

To see how these methods can be applied in a more realistic environment, I have adapted the Simple Bind project that uses the Pubs database to create a master detail view of publications and their respective titles. You can download the project files here.

Conclusion

As a developer it’s frustrating to have so many choices when it comes to something as simple as writing a query. This is especially the case when working in teams, you could easily find yourself picking up a project that’s been worked on by a number of developers and has a combination of all of these methods. I suggest that before you start implementing the EF into live projects, you take a look at all the techniques available and try to stick to one or two methods.