Deconstructing an ASP.NET MVC Website


Thanks to everyone who attended my presentation “Deconstructing an ASP.NET MVC Website” at the Carolina Code Camp on Saturday, October 10, 2009. I really enjoyed sharing some of the things I learned while building my first ASP.NET MVC website. As promised, I am posing my slide deck and resource links below. I’m still working on packaging the website code and promise to post it within a week or two.

Thanks for visiting and till next time,

author: Mark A. Wilson | posted @ Sunday, October 18, 2009 6:15 PM | Feedback (1)

Congratulations WNC .NET Developers Guild


1st Birthday Cake Hearty congratulations go out to Dave Kolb and everyone at the WNC .NET Developers Guild. They are celebrating their first anniversary tonight! Happy Birthday Dave!

The WNC .NET Developers Guild is an independent, all volunteer organization, dedicated to promoting Microsoft .NET technology and education to the software developer community of Asheville, NC and the surrounding areas.

Meeting on the second Tuesday of every month, Dave has had a very impressive start over the past twelve months. Their meeting have covered a wide range of developer-centric topics and have been given by some very big name presenters. Tonight’s meeting topic is cloud computing and how you can leverage the knowledge you have about .NET to take advantage of the various cloud technologies including offerings from Microsoft, Google and Amazon. While I can’t be there to help celebrate, I wish Dave and everyone best wishes and best of luck with years of continued success!

Thanks for visiting and till next time,

Technorati Tags: ,,

author: Mark A. Wilson | posted @ Tuesday, May 12, 2009 8:19 PM | Feedback (0)

Basic HttpWebRequest/Response


A friend recently asked how do you make a call to a web page via code. For example, the web page might be designed to return some data in a text-based format and filtered by query string parameters. (While this is more commonly done using a web service, it can also be accomplished by controlling the output of the HttpResponse object.) The following is a basic demonstration of how you might go about coding this in Visual C#:

   1: /// <summary>
   2: /// Makes a request to a Uniform Resource Identifier (URI) for accessing data from the Internet.
   3: /// </summary>
   4: /// <param name="requestUriString">The URI that identifies the Internet resource.</param>
   5: /// <param name="proxyAddress">The URI of the proxy server.</param>
   6: /// <returns>Returns a response to an Internet request.</returns>
   7: /// <exception cref="System.Exception">Returns a message that describes the current exception.</exception>
   8: /// <example>
   9: ///     GetWebResponse("http://twitter.com/DeveloperInfra", null);
  10: /// </example>
  11: private static System.String GetWebResponse(System.String requestUriString, System.String proxyAddress)
  12: {
  13:     System.Net.WebResponse webResponse = null;
  14:     System.IO.StreamReader stream = null;
  15:     System.String result = null;
  16:  
  17:     try
  18:     {
  19:         /* Initialize the web request. */
  20:         System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(requestUriString);
  21:         /* Optionally specify the User Agent. */
  22:         webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
  23:         /* Optionally create a proxy for the request object to use if you sit behind a firewall. */
  24:         if (System.String.IsNullOrEmpty(proxyAddress) == false)
  25:         {
  26:             System.Net.WebProxy webProxy = new System.Net.WebProxy(proxyAddress);
  27:             webRequest.Proxy = webProxy;
  28:         }
  29:  
  30:         /* Make a synchronous request and convert the response into something we can consume. */
  31:         webResponse = webRequest.GetResponse();
  32:         stream = new System.IO.StreamReader(webResponse.GetResponseStream());
  33:         result = stream.ReadToEnd();
  34:     }
  35:     catch (Exception ex)
  36:     {
  37:         //TODO: Log and handle the exception rather than just pass it back.
  38:         result = System.String.Format("Error: {0}", ex.ToString());
  39:     }
  40:     finally
  41:     {
  42:         /* Clean-up system resources. */
  43:         if (stream != null) { stream.Close(); }
  44:         if (webResponse != null) { webResponse.Close(); }
  45:     }
  46:  
  47:     return result;
  48: }

The first step is to initialize the web request by calling the Create method in the System.Net.HttpWebRequest class. It is preferred to use this method rather than the HttpWebRequest constructor. The method takes one parameter which is the URI for the web page you want to call including any query string parameters. For example, you could use the URI for my Twitter profile: “http://twitter.com/DeveloperInfra”. In the example above, the object that is returned from the method is cast as a System.Net.HttpWebRequest rather than the default generic System.Net.WebRequest object since I can control scheme of the URI. You can also optionally specify the User Agent and/or Proxy based upon your particular requirements.

Now that the web request has been initialized, you can actually make a synchronous request to the web page by calling the GetResponse method. Up until now, you have not actually called any web page or resource. The method returns a WebResponse object that contains the actual response from the web page request. Once you have that, you can quickly stream the data returned out of the object and convert it into a string that can easily be consumed elsewhere. In the case where I have used this code before, we took the XML string that was returned from calling a third-party web page and loaded it into an XmlDocument that was then used to update a SQL Server database table.

Works on My Machine Certification ProgramAs this is my first code example, I must point out the “Works on My Machine Disclaimer” within the sidebar. All postings on this blog are provided “AS IS” with no warranties, confer no rights, and offer exactly zero support. If it deletes files or kills your family pet, you have been warned. It might work great, and it might not. It hasn't been tested against the myriad of other products out there, but it works on my machine. Good luck!

Thanks for visiting and till next time,

author: Mark A. Wilson | posted @ Sunday, May 10, 2009 10:03 PM | Feedback (0)

Getting Started


Before we can start this journey together, I should take a moment to declare the foundation upon which everything will be built upon going forward. In other words, I need to tell you which languages and frameworks I currently make my living off of and will be blogging about. And I would like to do so without trying to intentionally fan the flames of the already overblown Microsoft vs. [fill-in-the-blank] wars. While I was in college, I thought I could do it all and be an expert in everything. After all, doesn’t every college grad think they will rule the world one day? Thus I took language courses in Assembly, C/C++, Pascal, COBOL, Visual Basic, Java, and HTML. While admittedly I was not an expert in any of them, I felt I had a good enough understanding of each to be successful coding almost any language after I graduated. However, not too long out of college, I quickly realized that I cannot be an expert in all things. (Shocking, huh?) I needed to quickly make a decision as to where I wanted to take my career. My decision was to focus on Microsoft-based solutions. Right or wrong, it was my decision and one that I have been extremely happy with. More on that another time. Today, I specialize in software development using the Microsoft .NET Framework, Visual C#, ASP.NET, and SQL Server.

With a solid foundation beneath us, I have two tips and tricks I’d like to share with those of you who may be new to software development and/or looking for a way to get a Microsoft-based development environment up and running quickly. Obviously, the first thing you will need is a computer. The more powerful and larger the computer, the better. If your computer has 2 GB of RAM or less, I would recommend using the Microsoft Web Platform Installer to setup your development environment.

The Microsoft Web Platform Installer is a free tool that makes it simple to download, install and keep up-to-date with the latest components of the Microsoft Web Platform, including Internet Information Services (IIS), SQL Server Express, .NET Framework and Visual Web Developer.

What is even more amazing is that not only will it download and install everything listed above, but it will also install popular ASP.NET and PHP applications! Everything you need to get your apps running in just a few clicks. Congrats to the Microsoft IIS and Web Platform teams for reaching out to the community and making something that just works!

If your computer has 2 or more GB of RAM, you might want to consider using a virtual machine to host your development environment. Microsoft Virtual PC and VMware Workstation are likely the most popular virtualization programs currently being offered. Both programs host virtual machines that can run their own operating system and applications just like a “real” computer. It’s a computer within a computer! By “virtualizing” your development environment, you can safely use beta tools and code without polluting – or worse, corrupting – your day-to-day computer. You can also safely format and reinstall your day-to-day computer without loosing your development environment.

What is even more amazing is that Microsoft makes it easy to get your hands on pre-installed and configured virtual machines! Better yet, they are free*! Simply go to the Microsoft Download Center and search for “VHD”. Then search through the results for the latest virtual hard disk image of the version of Microsoft Visual Studio that you want to use. After you download and extract the virtual machine, you will have everything you need to get your apps running in a virtual development environment.

*A word of warning before you start thinking a virtual machine is the cure for something it is not. For starters, with virtualization comes performance degradation. Virtual machines run slower than their “real” counterparts. Depending upon the specifications of your computer, you might not find working with a virtual machine enjoyable or worth your time. Secondly, virtual hard drive images are very, very large. We are talking several GBs in size. Downloading that many bites is not something you want to do on a dial-up Internet connection. It also means you need a lot of available disk space on your day-to-day computer. (I strongly recommended using an external USB hard drive if you only have one hard drive in your computer.) Finally, “free” usually means using a trail or time-restricted version that will expire. As a matter of fact, you can easily loose your entire development environment if you don’t backup your files before a time-bomb renders your virtual machine unusable. In other words, use at your own risk.

Now that we have a solid foundation and development environment up and running using Microsoft-based solutions, let’s keep moving forward.

Thanks for visiting and till next time,

author: Mark A. Wilson | posted @ Thursday, April 30, 2009 10:12 PM | Feedback (0)

First Steps Forward


Hello. My name is Mark Wilson and this is my first blog entry.

I took my first steps in the early 1980s when my father brought home the Commodore 64 followed very shortly by the Osborne Executive. I was hooked. Since then, I have never been without at least one computer. As a result, I pursued a career in Information Technology with the explicit focus of building software applications that help – not hinder – people. After all, computers are overly complicated and generally unfriendly enough. We don't want to make things worse.

So what exactly is Developer Infra? It is my search to identify what it takes to enable software development. The key word being enable:

  1. provide somebody with means: to provide somebody with the resources, authority, or opportunity to do something
  2. make something possible: to make something possible or feasible
  3. give somebody or something legal authority: to confer legal power or authority on somebody or something
  4. cause something to start to operate: to make a piece of equipment or computer system functional

-MSN Encarta Dictionary definition of enable.

Like computers, software development is often overly complicated and generally viewed unfriendly. It does not need to be that way. In my opinion, we need to utilize things that will allow us to focus exclusively on business logic. After all, that is what brings real value to the business and that is our ultimate goal. Right?

I invite you to join me on this journey. Along the way, I hope to collect useful developer infra – articles and links that refer a reader to things that enable software development. I do not pretend to be an expert on all things nor a self-proclaimed computer guru. Even I recognize I have much to learn. So I also invite you to leave a comment. Please do not hesitate to share your knowledge or provide constructive criticism. Together, we can keep moving forward.

Around here, however, we don’t look backwards for very long. We keep moving forward, opening up new doors and doing new things - because we're curious. And curiosity keeps leading us down new paths. We're always exploring and experimenting.

-Walt Disney

Thanks for visiting and till next time,

author: Mark A. Wilson | posted @ Sunday, March 22, 2009 2:01 AM | Feedback (0)