ASP.NET MVC3 / Razor: How to Get Just the Uri for an Action Method

I normally wouldn’t post something this small to my blog, but this issue bothered me so much when I was working on some Twitter @Anywhere + jQuery integration in ASP.NET MVC3 that I couldn’t help but share it.

Issue: You’re using ASP.NET MVC3 and want to be able to place a relative Uri for one of your ASP.NET MVC controller’s action methods in a block of JavaScript or anywhere else, and you want to be able to do it without having to parse it out of an Html.ActionLink output or anything else. What built-in helper method do you use?

Solution: The answer is that you use the Url.Action method, which yields a relative Uri, as you’d expect.

Observe the code below:

Quick and Dirty Feed Parser 1.0 Released!

Without further adieu, it’s my pleasure to announce that the full 1.0 release of Quick and Dirty Feed Parser is now available to download on Codeplex.

Here are the main reasons why you should care about Quick and Dirty Feed Parser 1.01:

  1. Works on Windows Phone 7 and Silverlight 4;
  2. All IFeed objects now consume substantially less memory on average;
  3. All IFeed objects are now serializable;
  4. All IFeedFactory objects now support DI for injecting your own feed parsers; and
  5. Added an IsolatedStorageFeedFactory for working with RSS / Atom feeds in IS for all Silverlight and Windows Phone 7 developers.

Making QD Feed Parser run on Windows Phone 7 took some work – I had to rewrite the entire parsing library using LINQ-to-XML instead of XPath, but it was well worth it. The LINQ parser is now used by default in all IFeedFactory instances, but you can inject...

Read More

What Drives a Startup Founder?

I’ve been working on numerous projects since the year began, and on Sunday night I finally got around to watching The Social Network. My expectation was that the movie was going to be a breathless attempt by Hollywood to insert themselves in something cool and relevant, a tin-eared paean to their own importance. “Hey, we can be part of the social media revolution too – check out this awesome movie we made!”

But I was wrong – the movie was excellent. I assume that aside from some specific numbers regarding equity and valuation that the movie is a pretty accurate depiction of the early years of Facebook. I don’t know Mark, but from the movie I gathered that he was a socially challenged person who was very, very focused on getting one thing done.

What Drives Me

The image that gripped me most from The Social Network...

Read More

Getting Started with AppHarbor – Heroku for .NET

I’ve a lot of friends who are proficient Rails developers, many of whom who have left .NET for Rails.

The one piece of consistent feedback that I hear back from them is that it’s the frictionless Ruby-on-Rails ecosystem that is so attractive; moreso than the Ruby language or the Rails framework itself (although they like that too.)

Heroku, above all others, is hailed as a step forward in developer productivity and easy web application hosting and deployment.

Platform-as-a-Service (PaaS), which is what Heroku provides to Rails developers, is powerful because it eliminates much of the need to manage and maintain infrastructure. Instead of managing a number of virtual machines on a service like EC2, you manage a number of application instances or some other such abstraction. PaaS combined with a continuous build / deployment system is a powerful combination indeed and allows for unparalleled productivity for agile web...

Read More

6 Really Useful Windows Phone 7 Articles

I’m in the midst of working on a line of related Windows Phone 7 MVVM Light applications which are all built on the upcoming release of Quick and Dirty Feed Parser, which includes Silverlight and Windows Phone 7 support.

I found the following articles to be really useful in the course of trying to smooth out some performance problems, implement local caching, and are just generally good links to have around if you’re trying to do any serious WP7 development:

  1. Performance of Windows Phone 7 Applications – if you’re wondering why your UI seems sluggish, then you need to read this article. It explains how to use built-in tools to enable basic performance monitoring and has a great list of fixes for common performance problems.
  2. Using Isolated Storage on Windows Phone 7 – provides a great learn-by-example overview of how you can use IsolatedStorage in Windows...

    Read More

How to Use Asynchronous Controllers in ASP.NET MVC2 & MVC3

The primary reason I added asynchronous methods to Quick and Dirty Feed Parser 0.3 was because I wanted to use QD Feed Parser in conjunction with asynchronous controllers in ASP.NET MVC3.

MSDN has some excellent documentation which explains the ins and outs of asynchronous controllers in ASP.NET MVC, yet there aren’t many good examples of how to use it online. Given this, I thought I would make one.

Asynchronous Controllers in Theory

Here’s how asynchronous controllers work:

async controllers asp.net mvc

And in case my visual isn’t clear:

  1. A user sends a request to some resource on your server, i.e. GET: /controller/action
  2. Since the action method is part of an asynchronous controller, the processing of the request is handed off to a CLR thread...

    Read More

How to Make Any Operation Asynchronous in .NET

I’m in the middle of writing some updates to Quick and Dirty Feed Parser for use in a new personal project of mine; namely, I need to make QD Feed Parser work asynchronously so I can use it in conjunction with asynchronous controllers in ASP.NET MVC3, and eventually Silverlight + Windows Phone 7.

Asynchronous network IO is a breeze in every version of .NET since 1.1 – WebRequest and many others have supported asynchronous methods for as long as I’ve been using them. However, asynchronous disk IO, which I need to support in QD Feed Parser, is not something that comes so easily in .NET 4.0 and below.

StreamReader is the most user-friendly tool for reading files off of local disk because you don’t have to manage any buffers or do any of the sort of accounting that a class like FileStream requires[footnote:It should be noted that...

Read More

Upgraded to BlogEngine.NET 2.0, Updated Extensions

BlogEngine.NET 2.0 was released just before Thanksgiving this year, and it includes a bunch of major changes, the most noticeable of which is the drastically improved admin dashboard.

There are also a number of external-facing improvements too such as jQuery out of the box, SEO improvements, and so forth. I contributed one small improvement to BlogEngine.NET 2.0, and that was the alternative captcha engine I wrote – Recaptcha causes as many problems as it solves and was rife with bugs in BlogEngine.NET 1.6 [footnote: just ask the people who were trying to comment on my post on ASP.NET MVC3 Remote Validation the other day].

SimpleCaptcha

SimpleCaptcha was inspired by the captcha engine Jeff Atwood used on Coding Horror for so many years, where he asked his bots to politely type in the word “orange.” In that vein I decided to follow in his footsteps.

The default SimpleCaptcha out...

Read More

Quick and Dirty Feed Parser 0.3 Now Available

My Christmas gift to the developer community: Quick and Dirty Feed Parser 0.3 is now available on CodePlex!

The big feature added in this release is the ability to perform IFeedFactory.CreateFeed operations asynchronously both for disc IO and network IO. I added this to QD Feed Parser primarily to support the use of asynchronous controllers in ASP.NET MVC3, and to support Silverlight and Windows Phone 7 eventually.

All classes which implement the IFeedFactory interface now have some new members:

IAsyncResult BeginCreateFeed(Uri feeduri, AsyncCallback callback);

IFeed EndCreateFeed(IAsyncResult asyncResult);

IAsyncResult BeginDownloadXml(Uri feeduri, AsyncCallback callback);

FeedTuple EndDownloadXml(IAsyncResult asyncResult);

If you’re at all familiar with the Begin[Procedure] End[Procedure] asynchronous programming pattern in .NET, then the purpose of these functions should be self-evident. Internally, BeginCreateFeed and EndCreateFeed are dependent upon the output...

Read More

Fluent NHibernate: How to Create Bidirectional Many-to-Many Relationships with Additional Attributes on Relationship Table

Suppose you have a relationship that looks like this in your database:

fluent-nhibernate-complex-many-to-many-mapping

This is a common use-case. In this instance, I wanted to be able to create a table which would log all of the times an individual user read a particular item from an RSS feed. I used an identity key here instead of a composite key so I could take advantage of NHibernate’s auto-magical SaveOrUpdate feature.

Normally with a ManyToMany relationship between two entities in Fluent NHibernate you would simply define a HasManyToMany attribute on either side of the entity, and .Inverse one of them such that only one entity is actually responsible for persisting changes to the database.

In this type of relationship, where your many-to-many relationship actually has additional...

Read More

P.S. Get the latest from Aaronontheweb

Have my most recent essays and articles delivered directly to your mailbox.