25 Feb 2008

What I Learned About MVC On Day One

9 Comments Uncategorized

I am really blown back about how fast and easy MVC is to develop with.  I know the guys at Microsoft do a good job with their .NET coding, but I am really impressed by the forethought they put in to MVC.  It builds on top of the standard ASP.NET package, but does it in such a way that makes it lean on top of the already feature-rich (read bloated) ASP.NET Page object.  It really doesn’t feel like I have all that baggage anymore.

These are the following links that got me started designing my very first MVC application.

Keep a watch on my blog about for my posts about Unit Testing MVC and using Validators in the Routing table.  Also I am currently exploring if it is possible for my URL Rewriter and Reverse Proxy to be used in combination with the MVC Routing table.  I will keep you informed.

07 Dec 2007

SEO and C# Extention Methods

4 Comments Uncategorized

I previously talked about the importance of using the correct kind of redirect to optimize your website for search engines in an article titled. World Of HTTP/1.1 Status Codes. I just recently decided to create a C# Utility class to help me in this endeavor and to extended the far from complete HttpResponse.Redirect method. I am using a new C# 3.0 language extension called Extension Methods. Basically what the extension method does is, it allows you to, add methods to types that you don’t have the ability to modify, in my case the HttpResponse class.

I have created the following code to give me better control over my redirects in the HttpResponse class.

public static void Redirect(this HttpResponse response, int type, string url)
{
	response.Clear();

	switch (type)
	{
		case 301:
			response.StatusCode = (int)HttpStatusCode.MovedPermanently;
			response.StatusDescription = "Moved Permanently";
			break;

		case 302:
			response.StatusCode = (int)HttpStatusCode.Found;
			response.StatusDescription = "Found";
			break;

		case 303:
			response.StatusCode = (int)HttpStatusCode.SeeOther;
			response.StatusDescription = "See Other";
			break;

		case 304:
			response.StatusCode = (int)HttpStatusCode.NotModified;
			response.StatusDescription = "Not Modified";
			break;

		case 307:
			response.StatusCode = (int)HttpStatusCode.TemporaryRedirect;
			response.StatusDescription = "Temporary Redirect";
			break;

		default:
			goto case 302;
	}

	response.RedirectLocation = url;

	response.ContentType = "text/html";
	response.Write("<html><head><title>Object Moved</title></head><body>");
	response.Write("<h2>Object moved to <a href=\"" + HttpUtility.HtmlAttributeEncode(url) + "\">here</a>.</h2>");
	response.Write("</body></html>");

	response.End();
}

So now in your code you don’t have to jump through hoops to chance the StatusCode, StatusDescription, RedirectLocation, and ContentType, just so you can respond with a 301 Redirect instead of a 302 Redirect (the default for HttpResponse.Redirect and the most dangerous of the redirects from an SEO point of view). All that you need to have access to is the Response property from your Page or Context and you are good to go.

Response.Redirect(301, "http://www.coderjournal.com");

So that is all you need to do to give your self better control over your redirects in .NET. You can also use this same C# 3.0 Extension Methods for any object that you need to add a custom method on to.

19 Nov 2007

Visual Studio 2008 and .NET 3.5 Released

No Comments Uncategorized

Scott Guthrie has announced that Visual Studio 2008 and .NET 3.5 are now available for download and provides a tour of some of the new features.

  • If you are a MSDN subscriber, you can download your copy from the MSDN subscription site (note: some of the builds are just finishing being uploaded now – so check back later during the day if you don’t see it yet).
  • If you are a non-MSDN subscriber, you can download a 90-day free trial edition of Visual Studio 2008 Team Suite here. A 90-day trial edition of Visual Studio 2008 Professional (which will be a slightly smaller download) will be available next week. A 90-day free trial edition of Team Foundation Server can also be downloaded here.
  • If you want to use the free Visual Studio 2008 Express editions (which are much smaller and totally free), you can download them here.
  • If you want to just install the .NET Framework 3.5 runtime, you can download it here.