This is an old blog. My new blog is moved here.

ASP.NET MVC SEO url regression for indexed ASPX pages

12/29/2009

My love affair with with the ASP.NET MVC framework is becoming a mature relationship now, so now the real challenge comes: how do I migrate all my old websites, on the ASP.NET MVC platform, without losing all my search engine indexed ASPX pages?

As challenging as it may sound, it is actually really simple:

In the Global.asax configure your default route as something like this:

	//old urls:
routes.MapRoute(
"Default", // Route name
"{url}", // URL with parameters
new { controller = "Home", action = "Index", url = "" } // Parameter defaults
);

Make sure you put this as the last route rule, because this rule catches everything that comes in the url.

Then in the home controller you can write something like this:

	public ActionResult Index(string url)
{

//page content
StringBuilder sb = new StringBuilder();

//pageTitle
string pageTitle = "";

switch (url)
{
case "blog.aspx":

//gets page specific query strings
string blogId = Request.QueryString["id"];

sb.Append("the blog id was: " + blogId);

break;
default:

pageTitle = "index";

sb.Append("helo index");

break;
}

//final build out
ViewData["page_title"] = pageTitle;
ViewData["page_content"] = sb.ToString();

return View();
}

There is little more work you need to do by converting all your code blocks into strings which in most of my apps I am doing anyway, so that I can use them on page as well as in AJAX responses.

Namespace importing in JavaScript mimicking using

12/29/2009

This is nice little trick that I have first seen the Netflix guys do while back.

(function($, util){

//Createst Namespace Object
if (!window.FNG) {
window.FNG = {}
};

//Createst Namespace Object
if (!window.FNG.widgets) {
window.FNG.widgets = {}
};

//Createst shortuct
var m = window.FNG.widgets;

//Modal Popup class
m.divPopUp = {
create : function(title, content, percentageWidth){

},
destory : function(){

}
};

})(jQuery, FNG.strings.util);

Through the anonymous function, we can have a closure, and by using the function params in the self-invoking mechanism, we can "import" namespace into the closure. This is basically an equvalent of the C# "using System.Text ..." syntax. It also becomes a nice dependancy checking mechanism. If you accidently forget to include your framework file on the page, you will get an error on load indicating that the particular namespace is not present.

JavaScript ASP.NET like StringBuilder using the module pattern

12/29/2009

Here is a nicel ittle utility that will make your JavaScript code much cleaner while keeping the performance high: C#-like string builder.

Note that this "class" is using Douglas Crockford's module pattern, so not "new" operator is needed when creating an instance.

NameSpace.util = {
stringBuilder : function (){

/* StringBuilder
------------------------------

//Description:
works like a regular stringbuilder

//Example:
var sb = NameSpace.util.stringBuilder();
sb.append("hi ");
sb.append("dave");
sb.append(" !");
console.log(sb.toString());
*/

var s = [];
return {
// appends
append : function (v){
if (v){
s.push(v);
}
},
// clears
clear : function (){
s.length = 1;
},
// converts to string
toString : function (){
return s.join("");
}
}
}
}

Ajax Web Application Architecture

10/19/2009

I have spend quite some times now developing heavy AJAX apps now, so I would like to share some of the lessons learned.

Once you cross in the true AJAX world which means that you are running your web page single session, and all the actions can happen without refreshing the page, a whole new world of challenges opens, unknown in conventional web development. Here are some of the common mistakes and challenges that I have ran across.

1. Using too much of JSON this is a common one that I have seen across board. Junior developers usually start with making requests which just return HTML, later moving to JSON format, however never realizing that too much JSON may not be the best thing. In general it is not a good idea to send all the data in straight DB row/column format sterilized to JSON. The main challenged is once you receive data that is too row, it takes too much resources, and too much code to convert it to presentation HTML code.

2. Standard communication protocol: Since JSON is an object, it is a good practice to “wrap” all your requests into a standard protocol. This has a great benefit, because it allows you to mainstream your client scripts, especially for error handling. For instance, you can get inspired from web services when creating your own JSON object wrapper. In general something like: {status: 1, message : “success”, data: {jsondata: {}}} works great to start.

3. Abusing the session abilities: Last week I had a long discussion with one of my co-workers who is a server side developer. It looked like he felt in love the idea of an AJAX web app too much, and wanted to store in the window object all the data he could, so that the same call to the server would never be made twice. While this sounds like a great optimization strategy, it actually kills the browser very soon causing it to slow down and eventually to crash. Plush there are the infamous browser memory leaks… so your AJAX web app should not relay on the browser memory too much.

I home this helps you to build a better faster and more scalable web app code.

hot to make money online (on the internet)

9/30/2009

This is a rhetorical question of many internet scams. Everybody wants to make money fast and easy, from home on their home computer. But really, this is something even I want to do, and have been striving for a while. I figured, somebody who works on the internet, understands the internet and its business models has to be figure out how to make money from it.

Over passed 4 years, my main steps to accomplish this goal has been through setting up websites that would generate traffic and I could make money from advertising. As I am realizing, this is really a long shot. So many hours web into development maintenance and the results are "only" monthly paychecks in hounders of dollars minus hosting costs. I recently talked to a friend of mine from the Czech Republic, who is also in the "traffic generating/advertising selling" business, to get some ideas how to monetize some of my Czech properties (here is website about Brno turism for example), but did not get much advise, in a small market such as the Czech, you have to go after the big clients and that is not easy if you are small.

Lastly, there is commerce. If you sell stuff, you don't need the economics of scale like when running a social networking website in order to make money. I have been thinking about this for a while, and not I am giving this a test drive with ordering sample order of some luxury furniture from china and trying to sell it on ebay. This is kind of a step of despair, because selling stuff does not really require all my high tech internet skills, but I really want to find out if "selling" makes more money than "advertising"