Now that ASP.NET MVC preview 4 is out, Phil Haack did as promised and made available a working prototype of IronRuby + ASP.NET MVC integration. He wrote:
Now that Preview 4 is out, I revisited the prototype and got it working again. I use the term working loosely here. Yeah, it works, but it is really rough around the edges.
To be able to use Ruby with ASP.NET MVC there has to be some c# glue/bridge code, especially in global.asax, which loads the routing tables (via extensions) and points at a specially made Ruby Controller Factory:
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.LoadFromRuby();
ControllerBuilder.Current.SetControllerFactory(new RubyControllerFactory());
}
That glue code is placed in a c# library called IronRubyMvcLibrary, which also contains support for .rhtml view pages. The objects you need to use from within the view page is accessible through Ruby global variables - $model, $response, $html and so on.
As John and Phil points out, this is a prototype and a test to try out a few things with IronRuby and MVC, and I think it's cool. Much will change over time, like how they use instance variables on the controller to pass data to the view.
This is a step towards something which may become quite popular in the Ruby community, and perhaps to Rails people who has to, or wants to, write web apps on the .NET platform in the future. For those that hasn't been looking at IronRuby yet and want to have some fun with this - note that you don't have any intellisense or anything lika that in Visual Studio yet.
Justin Etheredge wrote a detailed step-by-step blog post about how to download, build and get IronRuby up and running which is really good.
There is also the new wiki on the official IronRuby web site (www.ironruby.com) which covers the same topic and also has a few code samples that might get you going a few steps further - look at the FAQ pages.
Rob Conery did another excellent episode of his MVC Storefront series the other day where he ripped out his user membership code and replaced it with OpenId.
Implementing the whole OpenId protocol yourself isn't necessary as there are some great libraries for you out there which makes it really, really simple to use and integrate with both WebFoms and A SP.NET MVC. Rob uses the DotNetOpenId library to authenticate the user but didn't show how to fetch user details like the user full name.
Well, this is possible using Attribute Exchange which is a way of transferring information about the user between the OpenID provider and relying party. The DotNetOpenId library supports this too, and it just requires a small change to the DotNetOpenId code samples I've seen out there.
First, most people redirect to the provider like this:
openid.CreateRequest(id).RedirectToProvider();
But instead, create the request manually and add extension requests to fetch user information (like the name for example) to it before redirecting:
var openidRequest = openid.CreateRequest(id);
var fetch = new FetchRequest();
fetch.AddAttribute(new AttributeRequest("http://schema.openid.net/namePerson"));
openidRequest.AddExtension(fetch);
openidRequest.RedirectToProvider();
Just keep on adding the attributes you're interested in, like email, website etc. Remeber to inform your user about you wanting to fetch the extra information before doing the authentication.
After a successful OpenId authentication the provider redirects back to your site and you normally authenticate and redirect like this:
switch (openid.Response.Status)
{
case AuthenticationStatus.Authenticated:
FormsAuthentication.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, false);
//...snip...
Now, before the redirect statement, you have the chance to fetch out the attributes you asked for from the OpenId response, like this for example:
switch (openid.Response.Status)
{
case AuthenticationStatus.Authenticated:
var fetch = openid.Response.GetExtension<FetchResponse>();
if (fetch != null)
{
//assuming we got data back from the provider - add sanity check to this :)
var name = fetch.GetAttribute("http://schema.openid.net/namePerson").Values[0];
//...store name in session or something...
}
FormsAuthentication.RedirectFromLoginPage(openid.Response.ClaimedIdentifier, false);
//...snip...
Note that DotNetOpenId library offers a few "well known" attributes as enums which all uses the "axschema.org" schema, but they do not work with the myOpenId provider. That's why I'm using the "schema.openid.net" schema instead.
Rakuto Furutani blogged about the attribute schema problems in a Ruby on Rails post:
myOpenID supports only some attributes that can be exchange with OpenID Attribute Exchange, but you should care about Type URI, because myOpenID doesn't support Type URI described on "http://www.axschema.org/types/". You should specify Type URI with "http://schema.openid.net/" instead.
It could be I'm using an older version of the DotNetOpenId library and it's been changed in newed releases. I have to check this out.
Also, Andrew Arnott has written a longer post on how to use DotNetOpenId's Attribute Extensions extension which you should read if you want some more in-depth sample code (he's using ASP.NET WebForms).
I thought this blog post by Matt Valerio was good, and it gave me a few ideas to use in a current test project. He wrote a helper method to be able to use anonymous types when calling a delegate or lambda in the ThreadPool:
public delegate void WaitCallback<T>(T state);
public static class ThreadPoolHelper
{
public static bool QueueUserWorkItem<T>(T state, WaitCallback<T> callback)
{
return ThreadPool.QueueUserWorkItem(s => callback((T)s), state);
}
}
And his example code for using this method:
ThreadPoolHelper.QueueUserWorkItem(
new { Name = "Matt", Age = 26 },
(data) =>
{
string name = data.Name;
int age = data.Age;
// Long-running computation
});
Cute, eh?

UPDATE: And this morning it works again! Amazing. Yesterday I tried everything together with the support guy on the phone - unplugged power, hard drive, network, everything - but it was RROD still after 8-10 retries. And now, 20 hours later it works again? Weird. I'll let the box run for a few hours today and tomorrow. If nothing crashes I'll call Xbox support again and hear what they've got to say about it.
ANOTHER UPDATE: And a few days later it really, really died so I sent it in for repairs. :) I just got it back today - it took about 2 weeks "door-to-door", which is not too bad considering it travelled to Germany for repairs and back again to Sweden. The motherboard replaced.
Some time ago our Xbox 360 here at home started to glich - the screen froze up after a few minutes with a short squeeky noise from the speakers, one of the red lamps on the front lit and I thought the Xbox was going down. I contacted the support center to have it repaired (I would have to pay for it because we've had it for a couple of years and the warranty didn't cover this error), but they had problems with their incident system for a couple of days and therefore couldn't submit repair request... I asked them to call me back or send me an email when the system worked again, but they couldn't do that (boooh). That made me a bit angry, and I kind of dropped the Xbox from a few inches of height into the floor... and it worked pretty well after that!
...until now that is. This morning we had a real proper RROD (Red Ring of Death) - hardware failure. Argh!
I called the support center again and was prepared to pay for the repairs, but I was told that Microsoft extended the warranty for RROD/hardware failures to 3 years - good! I just got the UPS lables to print out and stick onto the box and will arrange for UPS to pick it up on Monday. They said it might take up to 3 weeks to have the thing repaired and sent back to us, but there's not much I can do about that.
I guess we'll have to power up the old Xbox console now and play Worms for a while :)
Craig Shoemaker, the host of Polymorphic Podcast (a .NET podcast which is getting better and better all the time), published a great set of resources for ASP.NET MVC which will keep you occupied for hours.
Also listen to his shows on MVC. He's got interviews with both Scott Hanselman and Jeffery Palermo around this topic.
I'm not going to copy/paste his list, just go there and check it out if you're into MVC.
I just picked up this answer to a comment on ScottGu's blog:
I believe we will be showing using ASP.NET MVC with IronRuby and IronPython later this week at TechEd. I don't think we've finalized what the tooling support will be - but you will be able to use these as language options with ASP.NET.
It would have been cool to be at TechEd...
I just saw this interesting twitter entry from John Lam:
I've also seen messages on the IronRuby mailing list like these:
We're just in a big time crunch before RailsConf so we're pretty well implementing anything that we need to in order to get Rails to run.
I'm not at the conference - anyone know if they managed to amaze anyone there?
Update: John just published more information regarding IronRuby and Rails on his blog. Check it out - the IronRuby project is groundbreaking in many ways.
I've been monitoring the OpenID progress for a while now, and when I saw this post from Scott Hanselman about how easy it is to add OpenID support for ASP.NET MVC through the use of the DotNetOpenId package, I had to give it a try. It it sure wasn't hard at all.
If you go to the DotNetOpenId website and download their stuff, you even get sample code for ASP.NET MVC that you can copy/paste from. If you know some OpenID and some ASP.NET MVC it won't take more than a few minutes to get the integration working.
Cool thing is also that if you get yourself an ID on www.myopenid.com (which is just one of many OpenID providers), you get Information card/CardSpace support as well! Oh I wish more websites could support this, I don't know how many different accounts and passwords I've created the last years. Thank God for "forgot my password" links... :)
New to OpenID? Learn more about OpenID and get your own.
Did you know there's T4 (Text Template Transformation Toolkit) support inside VS2008 now? Add a file with the .tt or .t4 extension to your project and you got a T4 template which VS2008 will automatically run when you save it. If you're into this and want to try it out, go to http://www.t4editor.net/ and download the T4-editor from Clarius. It gives you proper editing support from within Visual Studio. They got a version for vs2003 as well.
This may not be as attractive as it used to be, now that we got designer tools for Linq to Sql, entity framework and so on to help us generate boilerplat code for database access, but I'm sure I can come up with some good use for this. The ASP3-like syntax is very easy to grasp, so basically there is no excuse for not using this if you know you're going to produce lots of code that looks or behaves the same. As long as you have some metadata to work from, be it a database, xml file or text file, I'm sure this can be of help to you. Ah yes, you can write the templates in either c# or VB.
Some T4 resources for you maybe:
Hilton Giesenow blogs about T4 and you can download a couple of VS T4 templates from him!
Oleg Sych has a large number of very, very good blog posts about T4, Oleg is THE T4 blogger out there.
The T4-editor website by Clarius has a couple of videos.
The Text Template documentation for vs2008 on MSDN.
On MSDN there's also a good intro video on the topic that you might want to look at if this is of interest to you.
More Posts
Next page »