ASP.NET MVC URLs in IIS 6 using Ionic ISAPI Rewrite Filter

Brian LeGros | July 24th, 2008 | programming  

Ok, so I am totally swiping this from Ben Scheirman's blog post, but I thought I'd consolidate my comments on his post into a summary post. I've been working with ASP.NET MVC for a month now and everything has worked out as expected when I run my applications from the built-in IIS instance in VS2008. When I deploy to my local development environment, however, I run into the well know URL issue associated with using IIS 6.0. I dug into scraping the interwebs and found Ben's post as well as a post from Steve Sanderson. Both posts did the trick to help me fix the problems I was experiencing. Please keep in mind, since this is a PoC project, I have no budget, but I was able to find a solution using OSS.

+1 Ionic Isapi Rewrite Filter

Here are the steps I went through to get things working:

  1. Install Ionic's ISAPI Rewrite Filter into IIS
    1. Download version the file IonicIsapiRewriter-1.2.14-bin.zip and unzip it.
    2. Copy the IsapiRewrite4.dll file under the /lib folder to C:\Windows\system32\inetsrv.
    3. Create a file named IsapiRewrite4.ini and copy it into the C:\Windows\system32\inetsrv folder.
    4. Use the following template for the INI file. This will be used to rewrite URLs to include a .mvc extension so that incoming HTTP requests will be routed to ASP.NET:

      1. # empty URL gets mapped to home controller
      2. RewriteRule  ^/$  /home [R]
      3.  
      4. # needed for URLs one token deep
      5. # map controller parts of urls to .mvc, ignoring the content directory
      6. RewriteRule  ^(?!/Content)(/[A-Za-z0-9_-]+)$   $1.mvc  [I]
      7.  
      8. # needed for URLs more than one token deep
      9. # map controller parts of urls to .mvc, ignoring the content directory
      10. RewriteRule  ^(?!/Content)(/[A-Za-z0-9_-]+)(/.*)?$   $1.mvc$2  [I]

      NOTE: We need two rewrite rules to account for URLs one token deep that do not have a trailing slash. For example, if we excluded the 2nd rewrite rule, the url "/home" would be rewritten internally to "/home$2". I'm not sure if this is intended behavior (PCRE rules don't seem to agree when I try rule 3 here with the previous example), but adding the 2nd rewrite rule prevents this from happening.

    5. Under "Properties" on the website you've created in IIS (via the IISAdmin), select the "ISAPI Filters" tab, and click the "Add" button.
    6. Use "Ionic Rewriter" for the value of the "Name" field, browse to C:\Windows\system32\inetsrv\IsapiRewrite4.dll for the file, and click OK.
    7. Stop the IISAdmin service then start the World Wide Web Publishing Service on the machine.
    8. NOTE: There are more detailed installation instructions in the download with more options, these are just the steps I took.
  2. Create a mapping for the ".mvc" extension in IIS to instruct ASP.NET to service these HTTP requests.
    1. Under "Properties" on the web site you've created in IIS (via the IISAdmin), select the "Home Directory" tab, and then click the "Configuration" button.
    2. Under "Wildcard Application Maps" click the "Insert" button, browse to the file C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll for the value of the "Executable" field, uncheck the box "Verify File Exists", and click the "OK" button.
  3. Add the following method to your web application's globals.asax.cs file in the Globals class:

    1. protected void Application_BeginRequest(Object sender, EventArgs e)
    2. {
    3.    HttpApplication app = sender as HttpApplication;
    4.    if (app != null)
    5.    {
    6.       if (app.Request.AppRelativeCurrentExecutionFilePath.Contains(".mvc"))
    7.       {
    8.          app.Context.RewritePath(app.Request.Url.PathAndQuery.Replace(".mvc", ""));
    9.       }
    10.    }
    11. }

  4. Restart IIS just to be neurotic, like me.
  5. Build, publish, and load your application up in a web browser to give it a try.

Using these steps, I was able to get ASP.NET MVC URLs working on IIS without having the change my routes, which was ideal for me. When the upgrade for IIS7 comes hopefully I won't have to do anything too involved.

I hope these steps are helpful to those who want to try to the same thing. If I left anything out, please let me know. Best of luck!

Moving into the .NET world

Brian LeGros | June 15th, 2008 | programming  

With my latest employer, I have taken the big dive into the .NET world. I've spent most of my career working with ColdFusion, Java, PHP, Flex and dabbled a little bit in the Ruby/Rails and Groovy/Grails world in addition to the obvious set of web technologies and standards that span all of these application languages. My limited experience with .NET was through some undergraduate and graduate work I did with C# as well as helping (if you can call it that) with an ASP.NET a long time ago with a colleague of mine. I am a application developer; even though I dabble in lots of different areas, the bulk of my knowledge is building applications in a corporate IT environment. I focus on implementing business requirements and managing technical concerns as it relates to the software development process. I've had jobs in the past associated with business and management roles but at the core I am a plain and simple application developer. As I've been getting my hands dirty in .NET over the last few months I figured I'd share some of my initial impressions. Please keep in mind, I may be looking at a lot of things in a very naive light, so read what I have as my opinion, ignorant or not.

With context out of the way, I have to say that so far working with .NET hasn't been a negative experience. There is the whole you're stuck with Windows thing, but since I'm in fully entrenched in the MS world now, I've been able to get past it. There have definitely been some nuances to get used to, but nothing extremely difficult to overcome. Here are a few comments on some of the things I've run into thus far:

  • Namespaces in C# aren't constrained by the file system with respect to partitioning your code. Initially this seemed like a nice decoupling, but I've found myself forming more of a dependency on tools to navigate my classes hierarchy rather than just looking into a folder.
  • There is no notion of a shared class path as there is in Java. If you want to get a hold of an assembly to use in your application you've got to find it and pull it in. I think there is a configuration option on an assembly that you can use to help, but I haven't had any experience using it.
  • Assemblies are pretty nice build artifacts. Versioning is addressed out of the box and integrated with the .NET framework. I'm not sure how they stack up against something like OSGI, but I'm enjoying having them around.
  • Everyone says the implementation for generics is better in C# than Java, but as an application developer I don't notice a difference except that I've been told I can use reflection on them in C#. C# also seems to have made a much larger use of them in their core over Java. It seems like stronger typing is a very important practice in the C# world than in my experience with the Java world, but that is probably biased based on how I've used Java.
  • There appears to be a very balanced view on uses for metadata (attributes) in .NET. Annotations in the Java world were a great addition to the language, but sometimes their use comes off as abuse; look at a JUnit 4 test suite class for a great example.
  • There are lots of accepted libraries available that are direct ports from the Java community such as NUnit, NAnt, Spring.NET, CruiseControl.NET, NDocs, log4net, etc. Getting comfortable with these libraries was pretty easy since I'd had experience with the Java equivalents.
  • The help systems in .NET leave much to be desired and make me long for Javadocs, Livedocs, RDoc, or anything else. I find myself clicking through a class definitions on MSDN and after two or three links I can finally get to a list of "members" that belong to a class, only to click another link to load another page to see more about the details of that "member". I have yet to find any easily usable API documentation.
  • .NET has a solid component model available out of the box. WCF is a really simple and tight implementation of a component architecture. Service-orientation is a focus with an emphasis on abstracting away protocols, execution environments, and exposing metadata for a more contractual usage. It has the feel of being an API built around WSDL 2 and many of the WS-* standards, but it goes by many of the concepts, although not by name, identified in Patterns of Enterprise Integration. It's compatible with synchronous and asynchronous operations and did I mention simple to use? I hope to do some posting about it later.
  • Getting used to assimilating applications into the bowels of the OS seems to be core to the .NET mentality. This is probably just a matter of perspective for the developer, but based on the examples I've seen thus far, the user folder, the registry, and Windows\system32 folder are popular hang outs for lots of applications. I've been met by quite a looks of confusion when I mention deploying applications without the use of some type of installer. There is a lot of power that you get from this tight coupling with the OS I've been told. Unlike my previous shops, writing cross-platform applications doesn't seem to be a priority for .NET developers, so tight coupling it is.
  • It took me listening to the episode of SER with Anders Hejlsberg to understand better it, but it appears to be that developing in .NET is meant to be an IDE integrated experience via Visual Studio. Regardless of the aspect of development I've worked with in .NET thus far, the development experience has been fairly consistent. There is always some visual representation of the code available (where applicable) and a debugger is always around and working no matter the context (desktop, web, etc.). At first it was so simple that I felt like I was missing something, but from what I have read and heard, as much work goes into VS as does the .NET framework, if not more. If anyone has used Netbeans for Java web development, it's a very similar experience in terms of its integration with the environment.
  • I've always seen code insight as a supplemental thing, relying on documentation for the majority of my work, but wow, code insight (intellisense) seems to be the major crutch on which a lot of .NET developers place themselves within VS. What's weird is that I don't notice anything different than what you'll experience when working with Eclipse and Java, in fact, the code insight seems to be limited to code only. I have yet to run into a situation where the IDE makes a suggestion on how something could be written or changed as IntelliJ does for Java. I will admit though, maybe I'm missing something.
  • The visual editors in VS seemed to get abused by .NET developers. I say abuse because quite a few .NET developers I've encountered can't talk to me about their code in any other context but how they dragged-and-dropped controls onto a screen and edited properties. Since I don't know the in's and out's of the tools quite yet, having a conversation is tough. I try to communicate in terms of language agnostic principles and patterns but most of the time all I get are blank stares and judgmental comments about how I am over complicating things.
  • MS alternatives exist in terms of the IDE and runtime, but they don't seem to be popular at all. I really like SharpDevelop as an alternative to Visual Studio. It's clean, easy to use, and integrates with a lot of OSS packages out of the box. Mono is available as a Linux-based .NET runtime that has a lot of .NET developers excited because of its potential to allow them to code for the Mac. I don't know any Mac owners that have Mono installed however, so I don't know if it's really a viable cross-platform solution.
  • I have some thoughts on ASP.NET web forms that I want to share, but I'll save that for my next post.
  • The developer community has always been important to me and I feel it's always important to remain active in the community in some capacity. As I've begun attending the local .NET user group meetings, I don't see a lot of topics that are not MS centric. There is no question that MS drives the releases of the .NET framework, but there have been lots of innovations coming out of the community that deserve attention. It feels like there are only a small minority of developers that actually utilize these contributions locally. I have yet to see any presentations on the various unit testing tools, build tools, ORM, IoC, etc. that have come out of this space. I do envy the direct support that MS has for its user groups, but I wonder if my expectations are too high.

In any case, so far the learning curve with .NET hasn't been very steep and when I do get to code I feel fairly productive. I should be posting in the next few days on my thoughts about ASP.NET web forms so I'm sure that will get me flamed, but it's a major part of the puzzle I'm having to work with that I feel needs some attention. Until next time.

To Oregon and Back

Brian LeGros | May 29th, 2008 | news  

It's been a whirlwind trip, but I've come and gone from the great state of Oregon. I spent a week in Hillsboro, a suburb of Portland, at vendor training for one of the biggest MS shops in the financial industry. While the training was very enlightening (more to come on that later), it should come as no surprise that I was excited to try to the local cuisine. Since we ate out at every meal, here are a few local places that I'd highly recommend trying out if you ever find yourself in the area:

  • Burgerville - Fast food chain that uses food directly from Oregon with milkshakes that rival those of Chick-fil-A (as far as fast food goes).
  • Camp 18 in Seaside - Tasty soups and bread, huge portions, and an amazing location.
  • Pizza Schmizza - Gourmet pizza by the slice.
  • Imbrie Hall - Great appetizers; try out the Cajun tots for some good bar food!
  • Thai Orchid - Great lunch specials and curries. If you like spicy food, ask for "extra hot"; "hot" works out to be a "medium".
  • Old Market Pub - Delicious specials and great atmosphere.
  • Mio Sushi - Fresh, delicious sushi as well as awesome Katsu Don and lots of Japanese lunch options.
  • Jake's Famous Crawfish - Classic staple of downtown Portland. Classy place with some of the most amazing salmon I've ever had in my life. The halibut is great too!

Please keep in mind, I am stealing all of these great suggestions from our trainer, so thanks to Michael for the excellent suggestions. We also had an opportunity to stop by Rose's Deli and Bakery and Stanford's which are descent places to check out as well.

No trip would be complete however without some great beers and Oregon is famous for its microbreweries. Let me just tell you, tasting is believing. Most every local restaurant is equipped with its own brew and I was fortunate enough to get a small sampling of the selection Portland has to offer. Below are the beers I'd recommend at least trying if you're looking to quench your thirst:

  • Imbrie Hall - Some super IPA with triple the hops, Ruby, and the Rubinator (Mix of the Ruby and a stout called the Terminator).
  • Old Market Pub - Mr. Toad's Wild Red Ale, Hot Tamale!, Black Magic Nitrogen-Powered STOUT, and the Honey Root Beer.

Last but surely not least, I have to give a huge shout out to Simeon and Ryan for taking the time out of their busy days to hang out. Both guys have helped out the Adogo with remote presentations, so nothing is better than traveling to meet the people with which you only get to chat. Thanks for showing us around!

Portland is a great city with a cool technical population and a very lay-back vibe. If you ever have the chance to visit, definitely give it a shot. If you have time, check out some of the pictures Zach took on the trip for a good laugh.

Some of my realizations about user groups

Brian LeGros | March 19th, 2008 | programming  

Tonight I headed over to the Space Coast .NET User Group meeting, which consequently meets at my new office. They were trying out a similar 2 topic format, as we do at the Adogo, and it went really well. We started at 6:30 PM and ended around 8:15 PM. This evening they covered Workflow Foundation and its tools in Visual Studio 2008 as well as approaches for working cross team by using shared binary interfaces (also went into dynamic assembly loading a little bit).

What really struck me as interesting at the group was the context for conversation that occurred throughout the night. Everyone was pretty much on the same wave length, or at least appeared to be, and was comfortable; this may have been because of most of them work at the same mega-company or that the group has just been going steady for a long time, however. In any case, it was funny to see that the discussions were very different than what I've been exposed to in the past at user groups. There was a baseline of understanding for the work that Microsoft has done with varied technologies and discussions ensued relating to their application, not necessarily what they were and how they worked. This may have a lot to do with the average age and experience in the room (a older"wiser" demographic), but it also could be me looking into things too much.

I think I am finally able to empathize with user group members who have been frustrated with the Adogo recently. I went to the .NET user group looking for exposure beyond what I read daily on the web. The topics interest me, but I want more detail to see if I am getting excited over something that maybe isn't worth it (and vice versa). I found myself looking for code examples during the presos more since I am new to the syntax, but not the concepts. I was eager to take advantage of the work the speaker brought the group. This was something I hadn't previously thought about in depth. I always assumed people didn't want to read the manual and I couldn't see why the same conviction I had for programming wasn't present in others. I think I now realize that, as are most things in life, it's a matter of perspective with respect to what's important to the developer as it applies to technology. This may seem like common sense, but I'm a pretty big moron. In fact, I look at the Adogo and realize, we're really in a similar boat as the .NET group. Adobe has laid out the majority of the pieces we find ourselves using and until we have a common understanding of their use, it may be unreasonable to expect conversations like what I witnessed tonight without first establishing a baseline. It definitely seems like the sentiment on the mailing list to say the least.

I've got the April meeting next month, so hopefully this insight can help me better understand the service that a user group can perform for the community and what I can do to aid in its success.