Postback Failing

I ran into a strange problem this week on a client’s .Net site I was working on. There were two pages where postbacks were being completely ignored. If you clicked on anything that required codebehind or postbacks to work, such as the login/logout button, the save button, etc., an HTTP POST would occur (verified by Firebug), but the server would ignore the POST and serve up the page as if you did a GET.

Interestingly, it worked great on IE and Safari, but failed on Chrome and Firefox. What was even stranger was that everything worked properly when debugging in Visual Studio, but the failure occurred when the site was deployed to IIS.

So the failure occurred only when running Firefox or Chrome against IIS. The same website with IE and Safari worked great, and the same website on Cassini worked great in any web browser.

Hmm…

I ended up using WinDiff to compare the HTML output differences between what was served up from Cassini (Visual Studio during debugging) and IIS. There was one line that was different:

On Cassini:

1
<form name=”aspnetForm” method=”post” action=”/default.aspx?” id=”aspnetForm”>

On IIS

1
<form name=”aspnetForm” method=”post” action=”/“ id=”aspnetForm”>

Read More

Sharepoint 2010 Custom Workflow Activites

(If you’re impatient, you can see the code before reading the article)

Sharepoint has a workflow engine, and you can develop workflows for Sharepoint using either Sharepoint Designer or Visual Studio. Today I’m going to focus on workflows that are created using Sharepoint Designer. A step in a workflow, such as “Copy item from List A to List B”, is called an Activity.

Sharepoint Designer comes with a number of activities out of the box, but you can use Visual Studio to create custom activities that are surfaced to Sharepoint Designer. For example, if you saw the existing workflow “Copy item from List A to List B”, but it wasn’t quite what you wanted, you could create a custom activity for “Copy item from List A to List B and List C”, and that activity would then show up in Sharepoint Designer when creating a workflow.

Lets dig into how you can create a custom activity for Sharepoint Designer using Visual Studio.

Read More

Generics

Ok, so I’m a little late to the game here. Generics came out with .Net 2.0, which was released back in 2005. I’ve used them a good bit, but today I was asked what particular advantages Generics had over what was available in .Net 1.1, and, not having worked with .Net 1.1, I wasn’t really sure. So I did some digging and figured I’d share my results, for what it’s worth.

In .Net 1.1, if you wanted to have a collection of objects, such as a linked list, a simple array-like list, a queue, or, in fact, if you wanted to make a class that made use of some object internally, but you wanted to make your data structure available to multiple internal types, you had several options, but they all had some significant limitations.

Lets look at some examples. Suppose, for instance, you wanted to create a queue class, where you could have a queue of int, string, or any other type such as car, pet, or person (other classes you need to define elsewhere). Here are your options in .Net 1.1:

1. You could just use the generic ‘object’ type, as seen below. The big disadvantage here is that you have to be very careful adding and removing items, because you could easily add an object of the wrong type and you wouldn’t know until run time when you hit an invalid cast exception.

1
2
3
4
5
public class Queue
{
public void enQueue(object o) { … }
public object deQueue() { … }
}

2. You could create a intQueue class, a strQueue class, and so on. The intQueue class would look like the code below. You would get type safety, but the big disadvantage here is that anytime you want to create a queue of a new object, you have to create a new queue class, such as petQueue, carQueue, personQueue. That’s a lot of duplicated code, which increases maintenance time and you could easily end up with inconsistencies between your queue classes.

1
2
3
4
5
public class intQueue
{
public void enQueue(int i) { … }
public int deQueue() { … }
}

Enter .Net 2.0 and Generics. In .Net 2.0, you can define your generic queue class as such:

1
2
3
4
5
public class Queue<T>
{
public void enQueue(T t) { … }
public T deQueue() { … }
}

Notice that we use the generic placeholder of T. T is whatever class you want it to be, but T is defined when you actually declare / instantiate an object of the Queue class. Here is how you would make use of the class:

1
Queue<int> myIntQueue = new Queue<int>;

Notice how we put int in between the < and > signs. This signifies to the compiler that we are creating a queue of type int. So if we take the queue of int and try to add a string to it, like this:

1
myIntQueue.enQueue(“ABC”);

The compiler will throw an error, telling us that we can’t add a string to a queue of int.

So there you go. Generics give us the ability to generically (i.e., in a template sort of way) declare data structures that encapsulate other types without knowing what the type is that we are encapsulating, and they provide compile time type safety.

Development Tools

I’m setting up a new development environment, and I thought I’d share the list of tools and technologies I’m putting into place there. Please add any you’d recommend in the comments. Everything here is free except the OS, SmartSVN, and RedGate SQL Source Control.

Operating System: Windows Server 2008 R2 x64 ($$)
Application Server: IIS 7 with .Net 4.0
Database Server: SQL Server 2008 Developer Edition R2 x64 ($35)
(yes, that’s right - Microsoft has a fully-featured version of SQL server for development that is dirt cheap)

Installation Tools used:

  • Web Platform Installer - tool to help install IIS, .Net, MVC, and other components
  • NuPack - helps to add extra assemblies / web.config merges, etc. for third party DLLs for your project

Read More

Migrating Umbraco from MySQL to MSSQL

So you’ve been running the Umbraco CMS for a while on MySQL, but you’ve been told you need to move it to Microsoft SQL Server. Does it sound intimidating? It doesn’t have to be. With the SQL script and instructions in this post, it’s not too bad. First, let’s start with an overview of the process.

Overview:
1. Use the Umbraco installer scripts to create blank Umbraco tables on your SQL server
2. Set up a linked database in SQL Server to your MySQL database
3. Migrate the data (using my script below)
4. Update your web.config to point to the new database

Read More

SVN Trouble

(If all you want to do is solve the same problem, you only need to add a Timeout 1800 line to your c:\program files\visualsvn server\conf\httpd-custom.conf file and restart Visual SVN server - you can, of course, adjust the number of seconds as you like)

First off, if you are doing any kind of software development and you aren’t using source control of some kind, you are missing out big time. I highly recommend source control. I use Visual SVN for the server and Smart SVN for the client, but there are lots of other great options out there. OK, on to the good stuff.

We have purchased licenses for RedGate’s SQL Source Control, which allows you to use SQL Manager to check in SQL objects into a SVN repository. Very cool. I had been using this for a short while, and I soon saw this error when trying to scan for changes:

Could not read chunk Size: secure connection truncated

Read More