These are the slides and video from my presentation at Tulsa TechFest 2010. The talk is a walkthrough of Ruby on Rails. From install to working application. Please leave feedback on your thoughts.
I have created my first ever video tutorial which I am showing to the world. I walked through my post “How to get ASP.NET MVC 2 working with Mono in 10 Steps“. I plan to make more videos in the future so future ones should be better.
There is a video at the end of this post walking through it.
Once you get it figured out its easy. I always like to try to get my asp.net apps to run on mono so that I can say they can. The itch to do that with MVC 2 came back around a week ago, and I thought like every other time it was going to be simple. After some good googling I came up short, except to learn that MVC 2 is in the core of 2.7 and in the core of 2.8
preview. (Updated Post Since Official Release of 2.8)
I am a person that has never had luck installing mono from source, until today. So this was an adventure that took me probably 8 hours to figure out from start to end, and something I can redo now in about 30 minutes, including compile time.
I am going to list all my steps and why so you can know what is going on too. These are the steps on a complete fresh install of Ubuntu 10.04 Server, after updating it.
Step 1: Dependencies
apt-get install build-essential bison gettext pkg-config autoconf libtool automake
build-essential, bison, and gettext are required for the actual compilation of the source code. Fortunately, if you don’t install one of them it will complain at you and tell you what you don’t have.
pkg-config, autoconf, libtool, and automake are required for mono itself and running the configuration even before compilation. If you don’t do this step it too will complain at you.
Step 2: Compile and Install Mono from Source
tar -xjvf mono-2.8.tar.bz2
The above is pretty basic and easy to understand. Just note the –prefix=/usr there so it installs all the mono apps to /usr/bin. I made the mistake of doing –prefix=/usr/bin/ and it installed everything /usr/bin/bin. It was not pretty trying to fix the problem.
Step 3: Compile and Install XSP Server
tar -xjvf xsp-2.8.tar.bz2
This creates several of the things you need to run your ASP.NET applications. Of note for later it creates the application mod-mono-server4 which is what you will use to run your MVC 2 application on the .NET 4.0 framework.
Step 4: Install Apache
apt-get install apache2 apache2-dev
Now it is time to install apache, if it isn’t installed already. Also be sure to install the apache2-dev package since mod_mono needs it.
Step 5: Compile and Install mod_mono
tar -xjvf mod_mono-2.8.tar.bz2
Just like above this is pretty normal. Specifically what this does is it creates a config file for apache and the apache module. It puts the mod-mono.so module in the correct place, but not the apache config file.
Step 6: Fix mod_mono.conf File Location
mv /etc/apache2/mod_mono.conf /etc/apache2/mods-available/
This will put the file in the correct location. At this point we should be able to do ‘a2enmod mod_mono’, but it doesn’t seem to work. I didn’t move this to the mods-enabled folder because I wanted to keep with convention.
Step 7: Setup Symlink to Enable Site mod_mono
ln -s /etc/apache2/mods-available/mod_mono.conf /etc/apache2/mods-enabled/mod_mono.conf
a2enmod creates a symlink to files from /etc/apache2/mods-available/ to /etc/apache2/mods-enabled. This is a good convention to hold on to so the above line does just that.
Step 8: Letting Apache take Hold of Changes
Everything “should” load up normally at this point. If not read through the output and see if you can’t figure out what isn’t correct.
Step 9: Setting Up Virtual Host
This is a normal vhost file you would use anywhere with ASP.NET. The only difference for the ability to render MVC 1 and 2 is the MonoServerPath line. The end of it should point to mod-mono-server4 instead of 1 or 2*. If you don’t change this you will probably get a “targetFramework” error with your web.config file.
Just drop your MVC 2 app in “/srv/www/net.example.net/public_html/” and move on to the next step.
*.NET 1.1 support has been dropped with this latest release so mod-mono-server1 probably wont be there.
Step 10: Getting it all Working
Now is time to reload the apache vhost configurations. This assumes you have a virtualhost file loaded and ready to go. For the first install of mono I like to just restart apache.
At this point you should be able to browse your MVC 2.0 app, from the URL you set. It was quite a thrill to get it working the first time. For a test I made an MVC 2.0 app in Visual Studio 2010 built it. Then copied all the files over the server and it worked out of the box, once the above 10 steps were done.
I hope this helps other people and it works for them. It was a lot of fun and I learned a lot getting this working. If you have any questions please feel free to ask.
Mentally and Environmentally RoR and ASP.NET are similar. I don’t mean technically though. Some approaches and thoughts are the same, and there are many many differences. These are a few of my experiences on starting to learn RoR and remembering my learning of ASP.NET as well.
I had a personal project I came up with to help me learn and remember Japanese. It is something that I haven’t seen before so would have been a fun project I could easily knock out in a weekend on ASP.NET, is fairly basic idea. However, someone challenged me to try to do it in Ruby on Rails, so I figured what the heck why not.
A little background on me is I like ASP.NET and it is my preferred framework, but I am open to doing things in other projects which is why I am decent with php as well. Ruby on Rails is something I have wanted to take a look at, but just haven’t taken the leap until now.
Digging Into My Experience
First, thing I did was try to get some legs on doing RoR. I know that I am a very visual learner when it comes to trying new things so I went to lynda.com and got the Ruby on Rails essentials videos and watched through the first couple of hours of the videos.
I have to say that it was a great introduction. While they were using an older out of date version of rails it was enough to get me started so I set out to start working on my app.
First hurdle was figuring out sqlite. I have never done anything with sqlite at all so I had to quickly get up to speed on this and fortunately it was easy. I find doing this a big nicer default over SQL Express, but nice to see a portable way to do db stuff. Also of note a more flat file type system is coming to .NET world so more mobility in development is going to be available.
If you talk to a few developers I know there is one thing I don’t like and that is code generation, I prefer to lean on a well written framework. I just plain don’t like generated code so I was happy to see that the script/generate stuff mostly just generated files and methods, no real code.
One thing I love about ASP.NET development is I don’t need to run IIS locally and have some big app running in the background to view my sites I can just used the built-in web server cassini, and sometime soon IIS express. Happily RoR uses a “built-in” server, I prefer mongrel over webrick.
Ruby took a little getting used to, but I tend to like it. I much prefer it over PHP and can say if I have any future projects where ASP.NET doesn’t fit I will move to RoR first over PHP. Ruby just looks so much better as a dynamic language than PHP so it makes coding easier and more consistent. A good well organized language is another reason I like C#/ASP.NET.
Much like learning anything else learning new things can be a bit tricky at first until you get used to it. I feel pretty confident with my ASP.NET skills, but it took a lot to get there. RoR is the same thing.
RAD is Fairly Useless
Much like ASP.NET RoR’s RAD is great for examples and trying to show the “power” of a framework. However, once you dig into it flaws tend to show up when you start relying on all the RAD code generated. I quickly hit this wall when I wanted to do a few specific things and couldn’t, this might also be my lack of knowledge on a few conventions.
ASP.NET is similar with its controls. There is a bit of use for them, but anything past the basics it is time to hang them up and get to some real work and good code architecture that is why I prefer ASP.NET MVC it is easier to work with.
Too Many Conventions
The “power” that is offered by convention over configuration is enormous and can offer some real speedups when it comes to developing in rails, I can see that. However, good documentation of these conventions are very sparse and confusing leaving me constantly confused by things that should seem fairly simple.
A specific example is path helpers and routing. I have, yet, to find anything that goes into more details than what scaffolding shows about setting up a route mapping so I can do edit_object_path(@object) in a link_to method in one of my views. While it “works” like it should there are conventions behind all of it I can’t seem to figure out, yet, making things not work right, so it leaves me using uglier solutions that are brittle.
Barrier to Entry
This is the key area that RoR is similar to ASP.NET and I could be totally wrong about it only using RoR for 1 week. Both seem to be easy at first, but things quickly get more complicated until you figure out more about what is going on in the framework, and the proper way to do things.
In this case RoR has one thing going for it, for me. I am not trying to learn a new language, a framework, plus a web framework all at once. I have good experience with MVC using ASP.NET MVC and CodeIgniter on PHP.
Much like ASP.NET/.NET world documentation is too advanced, most of the time, when it even exists in RoR world. There isn’t enough stupid people examples of how to do things. The benefit of PHP world is its the first thing a lot of new developers learn so there is an abundance of beginner, beginnermediate, and intermediate examples of things allowing people to grow a little more easily.
Conclusion / Next
This is meant as a chronicle of my experience doing RoR development so I am obviously going to misunderstand and do things wrong, but for now RoR feels like a big hill to climb like ASP.NET used to be. The key thing is I need to learn how things are done in the ruby/ruby on rails world to make life a bit easier. I am used to the .NET world so time to get used the Ruby world too.
I had planned to post on how I got my environment setup for doing RoR development using 2.3.8, but seeing as how RoR 3.0
should be coming out soonjust released I will hold off and start over from scratch on it and get a bit more technical in future posts.
I want to thank all those that came to my talk. I have added the files for you to download. Just a note you will need to edit web.config file for connecting to the DB.
This is something that a lot of sites have to verify that the user’s e-mail is valid and seems like it would be complex, but there is a very easy way to do it. This is going to be a 2 part series, maybe a 3rd still thinking about it. First, I will give you the resources to learn about and setup the asp.net membership system and explain the concept of how we are going to activate the account. Part 2 will be a re-explanation along with code.
I wanted to actually explain all the steps to doing the membership system setup, but I just can’t beat 4guysfromrolla.com. Here are the links to there multi-part series on most everything about the membership system. I use it every time I need to get started with the membership system.
Examining ASP.NET 2.0’s Membership, Roles, and Profile:
Part 1 – learn about how the membership features make providing user accounts on your website a breeze. This article covers the basics of membership, including why it is needed, along with a look at the
SqlMembershipProviderand the security Web controls.
Part 2 – master how to create roles and assign users to roles. This article shows how to setup roles, using role-based authorization, and displaying output on a page depending upon the visitor’s roles. Part 3 – see how to add the membership-related schemas to an existing database using the ASP.NET SQL Server Registration Tool (
Part 4 – improve the login experience by showing more informative messages for users who log on with invalid credentials; also, see how to keep a log of invalid login attempts. Part 5 – learn how to customize the Login control. Adjust its appearance using properties and templates; customize the authentication logic to include a CAPTCHA. Part 6 – capture additional user-specific information using the Profile system. Learn about the built-in
Part 7 – the Membership, Roles, and Profile systems are all build using the provider model, which allows for their implementations to be highly customized. Learn how to create a custom Profile provider that persists user-specific settings to XML files. Part 8 – learn how to use the Microsoft Access-based providers for the Membership, Roles, and Profile systems. With these providers, you can use an Access database instead of SQL Server. Part 9 – when working with Membership, you have the option of using .NET’s APIs or working directly with the specified provider. This article examines the pros and cons of both approaches and examines the SqlMembershipProvider in more detail.
Email Activation Concept
The overall concept is fairly simple. You register then receive an e-mail that you have registered along with an activation URL. When you click on the URL it goes to the site and activates your account proving that you are real and there is a real e-mail address.
The easiest way to do this is the following.
- User Registers
- Once registration guid is created
- guid is put into a table associated with a username
- E-Mail is sent to user with a url based on the GUID something like ( http://example.com/Activate.aspx?key=1234-1234-1234 )
- User Opens Email and click link
- Person comes to activation page
- Activation page reads querystring and associates the string with guid in db. If a match executes code to “approve” account for use
- User can login.
There are a few key things:
- You need an association table. Something that will hold the guid and username for later verification.
- Create the GUID and get username _after_ account has been created and commit to above table.
- Build the activation URL and Send the e-mail
- On the activation page read the query string and find association in association table and retrieve the username if association exists between username and guid.
- if a username is returned call the membership api and activate the account.
Remember though that when building the site be sure to set the property where when the user registers the account is not automatically approved.
This is a very useful and needed feature in some respects and highly used. The concept is fairly simple and with the membership system it continues to stay fairly simple. Please feel free to try this on your own and report back any issues you came across and how you overcame them.
I will post part to in a couple of days. I am hoping on Sunday as a present to you all on my Birthday though we will see how that turns out.
One things that has always been utterly confusing in ASP.NET is the dang Web.Config file. For the beginner to ASP.NET it makes next to no sense and Visual Studio adds a whole bunch of stuff to it that I have no idea what it does. It is also so odd and confusing if I want to do basic config stuff in my application I have no idea how in the world to go about it.
Partly out of necessity and partly to rid myself of not knowing how the web.config works I have been spending time learning about it. I am first starting out with the basics. Getting something to work.
With most things I want to learn I completely bypass the "how" at first and get something basic to work, which is usually a "Hello World". That is what we are going to work on in this post. Lets just see something work. So these are the two objectives:
1) Set a configuration option we can use in our code
2) Allow for debugging our ASP.NET application
Now, we don't "need" a web.config to run basic .aspx pages, but if you want to anything more advanced than a one page site then you will need one.
Here is our web.config that we are going to look at today.
This is really all we need to set a configuration option to access in code and to allow for debugging our application. Please notice that everything is wrapped in:
That is important to note because all your config information should be under the root configuration node.
Custom Application Configuration
Next we have where we will set configuration options.
<add key="Hello" value="World" />
In the appSettings is where you will put configuration options that are like global variables to your WHOLE asp.net application. So in this case you will access the Hello key and it will return the world as its value. So the code you would use to access the config options is:
You will use ConfigurationManager object which access all the information in your web.config file. Since the Hello key is in the <appSettings> node then you would use AppSettings collection to access what key value pair you need. In this case accessing hello and it returns world.
Why would you ever need to use this? Well one things comes to mind. You might have a membership system that you want to turn on and off so you could have in the web.config:
<add key="Membership" value="false" />
In your code you might have it check to see if it is true or false if true then it displays login stuff for people to register and login if false it doesn't display it. It might look something like:
If(ConfigurationManager.AppSettings["Membership"] == "true")
//display login control
This is just a possibility of something you might want to do.
<compilation debug="false" />
Here we set whether we want to debug our application or not. I usually set this to yes as I have yet to write a bunch of code with out a bug. All you need to do is to change false to true and you will enable debugging in your asp.net application.
The web.config file is actually a little more simple than it appears once you understand more of what is going on with it. If you take learning it slowly and one little step at a time it is quite possible. I hope to cover a little bit at a time of the web.config as I learn more and more since it is quite important to learn.
Yesterday in the "Coolness of SubSonic" post I had a bit of asp.net markup (as I call it) that would display data in a data list from the data source. It specifically used.
<%# Eval("Name") %>
For a long time I have wondered how that worked I could never seem to figure it out until yesterday. Basically, you have an object that you bind to the data control like a datalist. In the case yesterday it was a Product class Object:
Well in the asp.net markup that we have below:
Notice in the Eval part it uses Name also notice from the product class above there is a name property. What ever property the object has you can use that in the Eval and it will display the data in there that comes from our collection of objects. In this case the Name property of our collection of Product Objects.
I know this wasn't a "cool" post, but it is something I was excited to finally understand so I thought I would post on it to help others understand hopefully.
When you read most tutorials about master pages they tell you that you just need the at directive at the top to declare its mater page and then only asp.net content in the rest well that gets confusing.
What needs to be said is you need the @ directive stating the master page to use, and you don’t need any html. However, you can use HTML and css and other things inside of the content page. You just don’t need the html that sets up the page such as:
You no longer need that. It leaves you free to insert pure content of any type without make sure that those setup tags are in your page.
Hope that helps someone.
I must say that master pages are really really cool. At first I was concerned that Master Pages was going to force everything that you did to be in tables thus taking CSS out of the picture. I was mainly concerned about this because I can see the benefits that CSS can offer to web developers and want to use this really cool and useful technology.
When I first saw Master Pages being used I would look at the code and see almost nothing but tables being used for positioning of objects and it was annoying because after all I want to use CSS. So I proceeded to start and learn CSS anyway hoping that I could just override the default output that Master Pages used.
Well I have learned quite a bit about CSS now, basically I am confident with it, and just took a look at Master Pages. I must say I was impressed by them the blew me away with the possibilities. I am still learning them so some of the problems I forsee are probably solved. Let me first explain a little bit about master pages first.
Master Pages is a new technology in ASP.NET 2.0 that allows for a unified look and feel of a website without having to go in and customize individual pages, which can take up hours. With master pages you make a sing master page that has the look and feel you want across all pages such as the most common things menu, banner, and footer. Now user controls reduced the time it took to do this significantly, but Master Pages is just where it is at.
Now CSS offers pretty much the same thing. You make up your classes for your divs with positioning font information yada yada yada. Now Master Pages makes it faster than CSS, but if it outputs to tables, then where are the web standards? This was my big worry. I want to make standards compliant websites using ASP.NET.
Well here is the cool part. You can use CSS to do the layouts on the Master Page. In fact Master Pages compliments CSS and vice versa. You now only have to make the CSS file, and apply all the classes and ids to one file instead of 20. Now tell me that is not awesome.
What does this mean?
Well it increases the possibilities of standards compliant ASP.NET websites. It allows for less time in development because now you can focus more on the code that is important instead of menial looks. You can now write the whole backend for that amazon.com clone and don’t have to worry about the useless front end.