Don't forget to...


Monday, August 8, 2011

Deploy an ASP.NET MVC 2 Web site on IIS 6.0

Hey sports fans!

Today I was given the task of deploying my web site to my development machine. With MVC 2 plugged-in to Visual Studio 2008, it should have been a cinch (with VS2010 and IIS7, it IS), but I ran into some roadblocks I thought I'd blog about.

So all I thought I would have to do is right click the ASP.NET project in the solution explorer while the solution was open in Visual Studio, and click publish, and then specify the directory to publish it to. Visual Studio was supposed to do the rest. But ACTUALLY it was much tougher. First I had to open the properties of the ASP.NET project, and go to the "Web" tab, and set it to run on an IIS server instead of a development server. THEN I took the step of right clicking the project and (publish...)ing it. But everytime I tried to navigate to http://localhost/ it would give me a weird error saying the directory was inaccessible.

The problem was that IIS had no mapping for paths without extensions. you see "localhost" maps to "localhost/home/index", but what IIS was expecting was something that ends in ".aspx" - so IF "localhost" mapped to "localhost/home/index.aspx", then the page would display and everything would be peachy. But it didn't. So here's how you map something with NO file extension (i.e. a "wildcard" mapping). (I learned it from here: haacked

1.) Open up IIS from the start menu.

2.) Expand the tree so that your website's name is displayed (underneath "Default Web Site").

3.) Right click your website, and go to the properties.

4.) Click Configuration...

5.) Click Insert under "Wildcard application maps"

6.) Enter the location of your aspnet_isapi.dll file (find it by going back and Editing the .aspx file extension in the previous window)

7.) Fill in the other fields the same as in the above pic, and click ok

8.) Keep clicking ok until you're back at IIS. Now try the webpage and it should work!

Saturday, August 6, 2011

Rate my design

Yesterday I worked on refactoring one of the components in my ASP.NET MVC2 project. If anybody's reading and knows anything about software, I'd be glad to have your feedback on the design.

The controller handles all the logic, taking requests from the web and processing/delivering the response. My models are basically just data-transfer objects, and the Views are each strongly typed to a model, so that it can access values given by the controller.

There are 3 different types of views, one inside the other.

The outermost view is not type cast to any model, it just calls some javascript that asynchronously loads _ServerView views into a div element. The _ServerView's are strongly-typed to ServerModel's. The _ServiceView holds the smallest bit of information, and they're loaded one-by-one for each _ServerView. The _ServiceView is type cast to a ServiceModel.

Using this structure, we can have any number of _ServerView views on a page, and any number of _ServiceView views for each _ServerView. This is stuff that the business-side would desire to be configurable. .......Any thoughts? HA!

Thursday, August 4, 2011

Models, Views and Controllers

The MVC design pattern is one of the most widely used design patterns around, but it's talked about so much by experienced developers that sometimes noobs can get mislead as to the meaning and purpose of it. So here's an overview of the design pattern and what it's parts are for.

We'll start with a high-level flow of events:

1.) The user interacts with the user interface, which sends a message to the controller.
2.) The controller receives the message, converts it into a form that the Model can understand and interact with, and then sends it to the Model.
3.) The Model accepts the new information, and makes changes to it's own state reflecting the new information that it's just received.
4.) The view detects the changes in the Model, and updates itself accordingly.
5.) Repeat 1 - 4.

This is very high level and can change a little with every implementation, but the overlying theme and idea is there. Also, the way in which the view detects the changes will vary a lot : it can query the model every so often, there could be an event fired when the Model changes that is detected by the View, or the Model can notify the View.


The Model is the representation of your application's data. Models contain most or all of the business logic of your application.


Views represent the user interface of your application. They provide your Controllers with data from the user, and provide the user with data stored in the application - in the Models.


Controllers connect the Views and Models together. They act as a translator between the two, taking data from the View, translating it into something the Model can understand, and then passing it on to the Model. They can also operate in the reverse direction in many cases.

If you want to use MVC in one of your ASP.NET web apps, checkout ASP.NET/mvc. And Ruby on Rails uses the MVC design pattern too!

Now, if anyone starts talking about how MVC helped them build a solid webpage, you can engage them in conversation. Maybe it's a cute girl who said it? Maybe you can impress her with your Ruby on Rails knowledge by reading the previous post too!


...Love you.

Wednesday, August 3, 2011

Connecting to an API written in C from C#

The last couple of days have been trying for me at work.

Fortunately, I learned something. I was working on an application that needed to connect to a 3rd party API that was originally written in C - like a billion years ago. There was good documentation on the software, but in order to connect to it in C#, I had to go online and find out how from somewhere else. So here's what you do:

First, make sure the API was installed on your system, so that the dll's are registered in the GAC.

Second, start a new project in C#, and create a new class. Make sure to import "System.Runtime.InteropServices". At the top of the class definition, do something like this:

public static extern int MessageBox(int h, string m, string c, int type);

Now, you'll have to know the signature of the methods you want to use from the API first. Anyway, once you declare that the function you want to use is defined externally, and you've told the compiler where it's defined, you can start using the function:

MessageBox(0,"API Message Box","API Demo",0);

This is great stuff to know. You might think that you could just reference the dll in the Solution Explorer in Visual Studio, but if it's not a valid .NET dll, it won't let you do so.

The tutorial I used to figure this stuff out is located here.

One more thing that might be useful to you is passing pointers to variables, especially if you're calling C functions. to do so, just declare the function with the keyword "ref" right before the parameter, like so:

public static extern int blahmethod(ref char[] someVariable, int otherVariable);

And then use ref again when calling the function:

var x = blahmethod(charArray1, someInt);

Tuesday, August 2, 2011

TryRuby today!

Evening code fans.

I'm making some progress on a software system that I'm building at work, and I've started to enjoy the process of finding a problem, creating a solution, and writing code to represent what I've come up with. But now I wanna try something new...

I've been hearing a lot about Ruby on Rails in recent times, and I'm highly interested in it at this point. For those of you who don't know, Ruby is an object oriented programming language, but it's different from Java and C# in that it's a scripting language, so it doesn't get compiled down to machine code before it's run. "Rails" is a framework written for the Ruby language that makes it ridiculously easy to create websites in a Model-View-Controller sorta way. Just to get a basic web server up and running requires only 2 super simple commands on the command line!

A Rails webpage differs from ASP.NET MVC (the stuff I'm using at work) in that it doesn't require Microsoft servers to host it - translation : possibility for FREE hosted webpages using services like Heroku. A few popular sites that run on Rails include :

Yellow Pages
Living Social

for a more complete and prettier list, click here.

Frickin' Twitter! Twitter runs on Rails! An open-source (oh yeah, it's open source too! and has a HUGE community for support, questions, and plug-ins & frameworks for anyone who wants to use 'em) web framework runs one of THE most visited site in the world!

SO all-in-all, I was excited about the possibilities, but I didn't know how to get into Ruby. I mean, learn a new language, just like that? Who's gonna teach me? I'm not even a graduate yet! Lo and behold, I found this awesome site called It hand holds you through the first bit of learning Ruby, and I mean it HOLDS your HAND! It tells you exactly what to type, and what Ruby's doing when you hit enter. I'm also planning on beginning reading a book on the Ruby language called Programming Ruby 1.9. Hopefully something comes of it. If you're interested in web dev, or find coding fun, click the link above to try it out!

Happy coding.