aspnetmvc

There are 98 entries for the tag aspnetmvc

JSON Hijacking

A while back I wrote about a subtle JSON vulnerability which could result in the disclosure of sensitive information. That particular exploit involved overriding the JavaScript Array constructor to disclose the payload of a JSON array, something which most browsers do not support now. However, there’s another related exploit that seems to affect many more browsers. It was brought to my attention recently by someone at Microsoft and Scott Hanselman and I demonstrated it at the Norwegian Developers Conference last week, though it has been demonstrated against Twitter in the past. Before I go further, let...

ASP.NET MVC Installer For Visual Studio 2010 Beta 1 And Roadmap

A little while ago I announced our plans for ASP.NET MVC as it relates to Visual Studio 2010. ASP.NET MVC wasn’t included as part of Beta 1, which raised a few concerns by some (if not conspiracy theories!) ;). The reason for this was simple as I pointed out: One thing you’ll notice is that ASP.NET MVC is not included in Beta 1. The reason for this is that Beta 1 started locking down before MVC 1.0 shipped. ASP.NET MVC will be included as part of the package in VS10 Beta 2. …...

An Alternative Approach To Strongly Typed Helpers

One of the features contained in the MVC Futures project is the ability to generate action links in a strongly typed fashion using expressions. For example: <%= Html.ActionLink<HomeController>(c => c.Index()) %> Will generate a link to to the Index action of the HomeController. It’s a pretty slick approach, but it is not without its drawbacks. First, the syntax is not one you’d want to take as your prom date. I guess you can get used to it, but a lot of people who see it for the first time kind of...

ASP.NET MVC For Visual Studio 2010 Beta 1

I apologize for not blogging this over the weekend as I had planned, but the weather this weekend was just fantastic so I spent a lot of time outside with my son. If you haven’t heard yet, Visual Studio 2010 Beta 1 is now available for MSDN subscribers to download. It will be more generally available on Wednesday, according to Soma. You can find a great whitepaper which describes what is new for web developers in ASP 4 which is included. One thing you’ll notice is that ASP.NET MVC is not included in Beta 1. The...

Donut Hole Caching in ASP.NET MVC

A while back, I wrote about Donut Caching in ASP.NET MVC for the scenario where you want to cache an entire view except for a small bit of it. The more technical term for this technique is probably “cache substitution” as it makes use of the Response.WriteSubstitution method, but I think “Donut Caching” really describes it well — you want to cache everything but the hole in the middle. However, what happens when you want to do the inverse. Suppose you want to cache the donut hole, instead of the donut? I think we should nickname all of...

Put Your Pages and Views on Lockdown

As I’m sure you know, we developers are very particular people and we like to have things exactly our way. How else can you explain long winded impassioned debates over curly brace placement?  So it comes as no surprise that developers really care about what goes in (and behind) their .aspx files, whether they be pages in Web Forms or views in ASP.NET MVC. For example, some developers are adamant that a page should not include server side script blocks, while others don’t want their views to contain Web Form controls. Wouldn’t it be great if you...

ASP.NET MVC NerdDinner Walkthrough

At long last, the book that I worked on with Scott Hanselman, Rob Conery, and Scott Guthrie is in stock at Amazon.com. To commemorate the book being available, the two Scotts worked very hard to convert the free eBook of chapter 1 (the end-to-end walkthrough) from the PDF into a series of HTML articles. This is a great series which walks through the construction of the NerdDinner website. It touches upon most of the day-to-day aspects of ASP.NET MVC that you’ll want to know. It’s a great way to start understanding how the pieces largely fit together. ...

Scripting ASP.NET MVC Views Stored In The Database

Say you’re building a web application and you want, against your better judgment perhaps, to allow end users to easily customize the look and feel – a common scenario within a blog engine or any hosted application. With ASP.NET, view code tends to be some complex declarative markup stuck in a file on disk which gets compiled by ASP.NET into an assembly. Most system administrators would first pluck out their own toenail rather than allow an end user permission to modify such files. It’s possible to store such files in the database and use a VirtualPathProvider to load...

Using jQuery Grid With ASP.NET MVC

Continuing in my pseudo-series of posts based on my ASP.NET MVC Ninjas on Fire Black Belt Tips Presentation at Mix (go watch it!), this post covers a demo I did not show because I ran out of time. It was a demo I held in my back pocket just in case I went too fast and needed one more demo. A common scenario when building web user interfaces is providing a pageable and sortable grid of data. Even better if it uses AJAX to make it more responsive and snazzy. Since ASP.NET MVC includes jQuery, I figured it’d be...

TipJar: Title Tags and Master Pages

There are a couple of peculiarities worth understanding when dealing with title tags and master pages within Web Forms and ASP.NET MVC. These assume you are using the HtmlHead control, aka <head runat="server" />. The first peculiarity involves a common approach where one puts a ContentPlaceHolder inside of a title tag like we do with the default template in ASP.NET MVC: <%@ Master ... %> <html> <head runat="server"> <title> <asp:ContentPlaceHolder ID="titleContent" runat="server" /> </title> </head> ... What’s nice about this approach is you can set the title tag...

Anatomy of a Cross-site Request Forgery Attack

A Cross-site request forgery attack, also known as CSRF or XSRF (pronounced sea-surf) is the less well known, but equally dangerous, cousin of the Cross Site Scripting (XSS) attack. Yeah, they come from a rough family. CSRF is a form of confused deputy attack. Imagine you’re a malcontent who wants to harm another person in a maximum security jail. You’re probably going to have a tough time reaching that person due to your lack of proper credentials. A potentially easier approach to accomplish your misdeed is to confuse a deputy to misuse his authority to commit the dastardly act...

Open Source License For System.Web.Mvc

First let me begin by assuring you, this is not an April Fool’s joke. Exciting news! Scott Guthrie announced today that we have released the source code for ASP.NET MVC 1.0 under the Ms-PL license, an OSI approved Open Source license with all the rights that license entails. You can download the Ms-PL licensed source package from the download details page here. Just scroll down and look for the file named AspNetMvc1.Ms-PL.source.zip. My baby is growing up! A big thanks must go out to everyone involved in making this happen and to those who approved it. It’s...

ASP.NET MVC Sessions At Mix

After my critical post of the Mix website, I found this other site, http://sessions.visitmix.com/, which should have been prominently linked to from the main site because it has a working search bar and is fairly usable and flashy! I gave two sessions on ASP.NET MVC at Mix. ASP.NET MVC: America’s Next Top Model View Controller Framework ASP.NET MVC Ninjas on Fire Black Belt Tips As you can see, we tried to have a bit of fun with the session titles. If you’re not tired of hearing me talk about MVC,...

ASP.NET MVC 1.0 Released!

Today I’m happy to write that ASP.NET MVC 1.0 RTW (Release To Web) is now officially released. This was one of several announcements ScottGu made at the Mix 09 conference today, which I unfortunately missed because I was on a plane to Vegas enroute to Mix 09. I was busy  back at the mother ship making sure everything was in order for the release. Woohoo! It’s been nearly a year and a half since I joined Microsoft and started working on it and what a ride it’s been. Some highlights during that time: ...

Learn About ASP.NET MVC Via NerdDinner

I don’t know about you, but a great way to learn a new technology is to start using it. But to even start using it, it helps to be able to look at a real-world running application built on that technology. Combine that with source code and a walkthrough, and I think you have a winning combination. That’s where NerdDinner comes in. NerdDinner.com is the brainchild (and a big child at that) of Scott Hanselman. The concept is simple, let’s get nerds together over dinner so great ideas can flourish. The site is a great way to organize...

Hotfix for Installing ASP.NET MVC With Azure, Power Commands, or Resharper

Yesterday, I wrote about troubleshooting Windows MSI Installers and talked about the pain we here feel when an installation fails. Turns out, it’s not always our fault. ;) It appears there’s a hotfix released for Visual Studio which addresses a problem with installing ASP.NET MVC when you have a third party add-in installed. I mentioned the three above because they are among the most commonly used add-ins which run into problems. You can read about the Hotfix on the Visual Web Developer blog or simply go here to download it. Note, that this doesn’t solve the problem for...

Troubleshooting Windows MSI Installers

UPDATE: I updated this post slightly to address some good criticsm from Rob Mensching by removing the MsiZap section. Note that this post does not blame the Windows Installer for the few problems we have with ASP.NET MVC installations. The major culprit tends to be either devenv /setup or ngen.exe. The point in this post is to provide tools for those who are very careful, know what they are doing, and really want to take a peek at how the installer works. These tools can help provide insight to whether the two culprits I just mentioned really are...

ASP.NET MVC Release Candidate 2

Today we’ve made the Release Candidate 2 for ASP.NET MVC available for download. This post will cover some of the changes with ASP.NET MVC we made in response to internal and external feedback since our last Release Candidate. Let me provide the quick and dirty summary, and then fill in the details. Setup will now require .NET 3.5 SP1 Bin deployment to 3.5 host without SP1 still possible New server-only install mode Now onto the details Setup Requires .NET Framework 3.5 SP1 ...

I’m Speaking At Mix 2009

I finally have my registration worked out and I’m officially going to Mix09 this year! Woohoo! Not only am I going, but I’ll be speaking at Mix for the first time, so be sure to come by and say hi. I’ve mentioned this before, but Mix is easily one of my favorite Microsoft conferences. Jeff Atwood said it well: MIX is by far my favorite Microsoft conference after attending the ’06 and ’07 iterations... What I love about Mix is that it ... ...

IronRuby ASP.NET MVC With Filters

Last July, I blogged about an IronRuby ASP.NET MVC prototype Levi and I put together with John Lam and Jimmy Schementi of the DLR team. It was really rough around the edges (and still is!) One of the benefits of doing that prototype was that it inspired all the work around action and controller descriptors in ASP.NET MVC (something I need to write more about later) which decoupled us from exposing reflection in our public API and improved the overall design of ASP.NET MVC greatly. This had the nice side-effect of making the implementation of IronRuby on top of...

Take Charge of Your Security

Today I read something where someone was comparing Web Forms to ASP.NET MVC and suggested that Web Forms does a lot more than ASP.NET MVC to protect your site from malicious attacks. One example cited was that Server controls automatically handled HTML encoding so you don’t have to really think about it. The idea here is that Web Forms automatically protects you from XSS attacks. My friends, I’m afraid this is just not true. Take a look at the following page code. <%@ Page Language="C#" Inherits="System.Web.UI.Page" %> <% //For demo purposes,...

T4 Templates in ASP.NET MVC

Here’s a little known fact about T4 Templates…well besides that they exist in the first place. Visual Studio 2005 had support for T3 templates. T4 is the natural successor to T3. T3 is also the abbreviation used when marketing the movie Terminator 3: Rise of the Machines. I heard that the names are related, but I haven’t confirmed it beyond a doubt, which seems appropriate given the title of the movie. But you didn’t hear that from me, deal? Dude looks ready to write some code! Although they’ve been around forever, I haven’t really dived into T4...

ASP.NET MVC RC Refresh

Hello there. :) On Tuesday, we announced the release candidate for ASP.NET MVC. While there is much new in there to be excited about and many many bug fixes, there were two changes introduced in the RC that broke some scenarios which previously worked in the Beta, as reported by customers. We’ve updated the Release Candidate with a refresh that addresses these two issues. You can use the recently released Microsoft Web Platform Installer 1.0 to install ASP.NET MVC RC Refresh. It happens to be a handy tool for installing not just ASP.NET MVC, but everything you might...

jQuery Delete Link With Downlevel Support

Earlier this morning, I posted on making a simple jQuery delete link which makes it easy to create a delete link that does a form post to a delete action. Commenters pointed out that my solution won’t work for down-level browsers such as some mobile phones, and they were right. I wasn’t really concerned about down-level browsers. One solution for down-level browsers is to render a proper form with a submit button, and then hide the form with JavaScript. Of course this takes a bit more work. Here’s what I did. I made sure I had the following script...

Simple jQuery Delete Link For ASP.NET MVC

UPDATE: I have a followup to this post that works for down-level browsers. In a recent post, Stephen Walther pointed out the dangers of using a link to delete data. Go read it as it provides very good coverage of the issues. The problem is not restricted to delete operations. Any time you allow a GET request to modify data, you’re asking for trouble. Read this story about something that happened to BackPack way back in the day to see what I mean. The reason that delete operations deserve special attention is that it’s the most common case...

Controls Collection Cannot Be Modified Issue with ASP.NET MVC RC1

In my last post, I announced the happy news that the Release Candidate for ASP.NET MVC is available. In this post, I say mea culpa for a known bug within this release. This bug is a consequence of a change we made in our default template. We know have a content placeholder in the <head> section of the Site.master page. <head runat="server"> <asp:ContentPlaceHolder ID="head" runat="server"> <title></title> </asp:ContentPlaceHolder> <link href="../../Content/Site.css" rel="stylesheet" type="text/css" /> </head> The benefit here...

ASP.NET MVC Release Candidate

At long last I am happy, relieved, excited to announce the release candidate for ASP.NET MVC. Feel free to go download it now. I’ll wait right here patiently. There have been a lot of improvements made since the Beta release so be sure to read the release notes. I’ve tried very hard to be thorough in the notes so do let me know if anything is lacking. We are also pushing new tutorials up to the ASP.NET MVC Website as I write this. Also, don’t miss ScottGu’s usual epic blog post describing the many improvements. There’s also a...

Handling Formats Based On Url Extension

Rob pinged me today asking about how to respond to requests using different formats based on the extension in the URL. More specifically, he’d like to respond with HTML if there is no file extension, but with JSON if the URL ended with .json etc... /home/index –> HTML /home/index.json –> JSON The first thing I wanted to tackle was writing a custom action invoker that would decide based on what’s in the route data, how to format the response. This would allow the developer to simply return an object (the...

Interesting use of XML Literals as a View Engine

Dmitry, who’s the PUM for ASP.NET, recently wrote a blog post about an interesting approach he took using VB.NET XML Literals as a view engine for ASP.NET MVC. Now before you VB haters dismiss this blog post and leave, bear with me for just a second. Dmitry and I had a conversation one day and he noted that there are a lot of similarities between our view engine hierarchy and and normal class hierarchies. For example, a master page is not unlike a base class. Content placeholders within a master page are similar to abstract methods. Content placeholders...

A Little Holiday Love From The ASP.NET MVC Team

A while ago ScottGu mentioned in his blog that we would try and have an ASP.NET MVC Release Candidate by the end of this year. My team worked very hard at it, but due to various unforeseeable circumstances, I’m afraid that’s not gonna happen. Heck, I couldn’t even get into the office yesterday because the massive dumping of snow. I hope to get in today a little later since I’m taking next week off to be with my family coming in from Alaska. But do not fret, we’ll have something early next year to release. In the meanwhile, we...

Redirect Routes and other Fun With Routing And Lambdas

ASP.NET Routing is useful in many situations beyond ASP.NET MVC. For example, I often need to run a tiny bit of custom code in response to a specific request URL. Let’s look at how routing can help. First, let’s do a quick review. When you define a route, you specify an instance of IRouteHandler associated with the route which is given a chance to figure out what to do when that route matches the request. This step is typically hidden from most developers who use the various extension methods such as MapRoute. Once the route handler makes...

ASP.NET MVC Northwind Demo Using the Spark View Engine

While at PDC, I met Louis DeJardin and we had some lively discussions on various topics around ASP.NET MVC. He kept bugging me about some view engine called Flint? No… Electricity? No… Spark! I had heard of it, but never got around to actually playing with it until after the conference. And the verdict is, I really like it. Spark is a view engine for both Monorail and ASP.NET MVC. It supports multiple content area layouts much like master pages, which is one thing that seems to be lacking in many other view engines I’ve seen, which only...

Known Installation Issues With ASP.NET MVC

I’m working to try and keep internal release notes up to date so that I don’t have this huge amount of work when we’re finally ready to release. Yeah, I’m always trying something new by giving procrastination a boot today. These notes were sent to me by Jacques, a developer on the ASP.NET MVC feature team. I only cleaned them up slightly. The sections below contain descriptions and possible solutions for known issues that may cause the installer to fail. The solutions have proven successful in most cases. Visual Studio Add-ins The ASP.NET MVC installer may...

ASP.NET MVC on IIS 6 Walkthrough

I’ve seen a lot of reports where people have trouble getting ASP.NET MVC up and running on IIS 6. Sometimes the problem is a very minor misconfiguration, sometimes it’s a misunderstanding of how IIS 6 works. In this post, I want to provide a definitive guide to getting ASP.NET MVC running on IIS 6. I will walk through using the .mvc or .aspx file extension for URLs first, then I will walkthrough using extension-less URLs. If you’re running into problems with IIS 6 and ASP.NET MVC, I recommend trying to walk through all the steps in this post,...

Combining JQuery Form Validation and Ajax Submission with ASP.NET

As I mentioned before, I’m really excited that we’re shipping jQuery with ASP.NET MVC and with Visual Studio moving forward. Just recently, we issued a patch that enables jQuery Intellisense to work in Visual Studio 2008. But if you’re new to jQuery, you might sit down at your desk ready to take on the web with your knew found JavaScript light saber, only to stare blankly at an empty screen asking yourself, “Is this it?” See, as exciting and cool as jQuery is, it’s really the vast array of plugins that really give jQuery its star power. Today...

New Line Quirk with HTML TextArea

Pop quiz. What would you expect these three bits of HTML to render? <!-- no new lines after textarea --> <textarea>Foo</textarea> <!-- one new line after textarea --> <textarea> Foo</textarea> <!-- two new lines after textarea --> <textarea> Foo</textarea> The fact that I’m even writing about this might make you suspicious of your initial gut answer. Mine would have been that the first would render a text area with “Foo” on the first line, the second with it on the second line, and the third with it on the third line. In fact, here’s what it renders using Firefox 3.0.3....

Rendering A Single View Using Multiple ViewEngines

One of the relatively obscure features of ASP.NET view rendering is that you can render a single view using multiple view engines. Brad Wilson actually mentioned this in his monster blog post about Partial Rendering and View Engines in ASP.NET MVC, but the implications may have been lost amongst all that information provided. One of the best features of this new system is that your partial views can use a different view engine than your views, and it doesn’t require any coding gymnastics to make it happen. It all comes down to how the new...

ASP.NET MVC In The Clouds

Quick question? What’s higher than a kite? No, it’s not me nor Cheech and Chong. It’s a cloud! Bad jokes (but funny video link) aside, Windows Azure, Microsoft’s foray into cloud computing, is getting a lot of attention right now. The basic idea behind cloud computing is you can host your application in the cloud and pay a monthly fee much like a utility such as paying for water and power. The benefit is you don’t have to deal with the infrastructure work and maintenance and you get “elastic” scalability, meaning your application can dynamically scale to...

The Future of WebForms And ASP.NET MVC

I’ve heard a lot of concerns from people worried that the ASP.NET team will stop sparing resources and support for Web Forms in favor of ASP.NET MVC in the future. I thought I would try to address that concern in this post based on my own observations. At the PDC, a few people explicitly told me, not without a slight tinge of anger, that they don’t get ASP.NET MVC and they like Web Forms just fine thank you very much. Hey man, that’s totally cool with me! Please don’t make me the poster boy for killing Web Forms. If...

A Case Study In Design Tradeoffs: Usability vs Discoverability

Usability and Discoverability (also referred to as Learnability) are often confused with one another, but they really are distinct concepts. In Joel Spolsky’s wonderful User Interface Design for Programmers (go read it!), Joel provides an metaphor to highlight the difference. It takes several weeks to learn how to drive a car. For the first few hours behind the wheel, the average teenager will swerve around like crazy. They will pitch, weave, lurch, and sway. If the car has a stick shift they will stall the engine in the middle of busy intersections in a truly terrifying...

Donut Caching in ASP.NET MVC

With ASP.NET MVC, you can easily cache the output of an action by using the OutputCacheAttribute like so. [OutputCache(Duration=60, VaryByParam="None")] public ActionResult CacheDemo() { return View(); } One of the problems with this approach is that it is an all or nothing approach. What if you want a section of the view to not be cached? Well ASP.NET does include a <asp:Substitution …/> control which allows you to specify a method in your Page class that gets called every time the page is requested. ScottGu wrote about this way back when in his...

Grouping Controllers with ASP.NET MVC

UPDATE: I updated the prototype to work against the ASP.NET MVC RC A question that often comes up is how do you group controllers when building a large application with ASP.NET MVC. Often, the question is phrased as whether or not ASP.NET MVC supports “Areas”, a feature of Monorail. According to the Monorail documentation, MonoRail supports the concept of areas, which are logical groups of controllers. All controllers belong to an area. The default area is an empty (unnamed) one While there’s no out of the box support for this in ASP.NET MVC, the extensibility...

Bin Deploying ASP.NET MVC

With the release of ASP.NET MVC Beta, the assemblies distributed with ASP.NET MVC are automatically installed into the GAC. System.Web.Mvc System.Web.Routing System.Web.Abstractions While developing an application locally, this isn’t a problem. But when you are ready to deploy your application to a hosting provider, this might well be a problem if the hoster does not have the ASP.NET MVC assemblies installed in the GAC. Fortunately, ASP.NET MVC is still bin-deployable. If your hosting provider has ASP.NET 3.5 SP1 installed, then you’ll only need to...

Hot New Presentation Tip

Before giving a presentation, I review Scott Hanselman’s top 11 presentation tips. Well I have a twelfth tip that Scott needs to add to his list, and he’ll vouch for this. A couple of hours before Jeff and I gave the ASP.NET MVC presentation (the video is now posted!), we played some RockBand in the Big Room (exhibition area). Playing Eye of the Tiger before a big talk has a great way of both pumping you up and loosening you up at the same time. When I ran into Scott and told him this tip, he said...

Model Binding To A List

NOTE: This post is out of date! I'll update it later. Using the DefaultModelBinder in ASP.NET MVC Beta, you can bind submitted form values to arguments of an action method. But what if that argument is a list? Can you bind a posted form to an IList<T>? Sure thing! It’s really easy if you’re posting a bunch of simple types. For example, suppose you have the following action method. public ActionResult UpdateInts(IList<int> ints) { return View(ints); } You can bind to that by simply submitting a bunch of form fields which each have the same name. For example, here’s an example of a form...

ASP.NET MVC Beta Released!

Today we finally officially released the beta of ASP.NET MVC (go download it already!). True, the release has actually been available online since yesterday as it was announced in a Keynote at VSLive by Scott Hanselman, but that was intended to be a special treat for attendees in what ended up being the worst kept secret in .NET-dom. As usual, to get all the details, check out the latest epic installment on ScottGu’s blog. Scott Hanselman also has a great blog post with good coverage as well. As I warned before, we no longer bundle the Mvc...

Web Platform Installer

I’ve used the term “drinking from the fire hose” when describing my first days at Microsoft. However, I believe that a lot of our customers feel this way when approaching the plethora of options for web application development on the Microsoft stack. This is feedback we’ve received from many sources and as Scott Hanselman pointed out, there’s a concerted effort to make things easier to find and understand here. Much of these efforts will take time to see fruition, but some of them are happening now. The new Microsoft Web Platform Installer Beta can get you up and...

Refreshing ASP.NET Dynamic Language Support

This afternoon we released a refresh of our DLR/IronPython support for ASP.NET, now called “ASP.NET Dynamic Language Support”, on our CodePlex site. This was originally part of our July 2007 ASP.NET Futures package, along with several other features. As updates to these features were made available, we would have liked to remove them from the package, but we wanted to wait till everything within the package was updated. Well that time has come. This CodePlex release contains two exceedingly simple sample applications, one for WebForms and one for ASP.NET MVC. It’s compiled against the latest DLR assemblies, and...

StackOverflow at PDC

First of all, I want to congratulate Jeff Atwood, Joel Spolsky, and their team for the release of StackOverflow.com. If you haven’t tried it out, I highly recommend giving it a shot. Be prepared, it’s addicting. Besides my 959 reputation score (which is actually pretty weak), the other thing about StackOverflow that excites me is that it’s built using ASP.NET MVC. So far, Jeff has mostly praised the experience of using ASP.NET MVC, though he’s had a few pain points that I’m now well aware of. :) I like StackOverflow so much that I asked Jeff to...

Speaking at Tech-Ed 2008 Hong Kong

If you happen to be in Asia around October 8-10, I’ll be speaking at Tech-Ed Hong Kong. Come by and say hi. I’m giving three talks, one on each day. October 8 11:45 AM – 1:00 PM ASP.NET MVC  - An alternative approach to building Web Applications October 9 ...

MvcFutures And ASP.NET MVC Beta

UPDATE: The MVC Futures assembly, Microsoft.Web.Mvc is available on CodePlex. Wanted to provide a quick heads up about the MvcFutures assembly within ASP.NET MVC CodePlex Preview 5. As mentioned in various places, this assembly contains various experimental features we are considering for future versions of ASP.NET MVC. When we release the BETA for ASP.NET MVC, it will not automatically be included in the project template by the installer. We’ve included it in the various previews for convenience, but we want the BETA installer to be as close to the RTM installer experience as possible. We will make sure that...

How a Method Becomes An Action

This is one of them “coming of age” stories about how a lowly method becomes a full fledged Action in ASP.NET MVC. You might think the two things are the same thing, but that’s not the case. It is not just any method gets to take the mantle of being an Action method. Routing Like any good story, it all begins at the beginning with Routing. By default, one of the routes defined in the MVC project template has the following URL pattern: {controller}/{action}/{id} When a request comes...

ASP.NET MVC CodePlex Preview 5 Released

Download the MSI and Release notes here. Last night we released ASP.NET CodePlex Preview 5 on CodePlex. Be on the lookout for one of those famous epic blog posts from ScottGu describing the release. In the meanwhile, the release notes contain short write-ups of what has changed. We didn’t originally plan to have another preview. However, we implemented a few significant chunks of functionality and were dying to get feedback so that we could incorporate it into the product before Beta. It helps that with five or so of these interim releases, we’ve become pretty efficient producing...

ASP.NET MVC Is Not Part of ASP.NET 3.5 SP1

I wanted to clear up a bit of confusion I’ve seen around the web about ASP.NET MVC and the .NET Framework 3.5 Service Pack 1. ASP.NET MVC was not released as part of SP1. I repeat, ASP.NET 3.5 SP1 does not include ASP.NET MVC. What was released with SP1 was the ASP.NET Routing feature, which is in use by both ASP.NET MVC and Dynamic Data. The Routing feature is my first Framework RTM feature to ship at Microsoft! We also shipped a bunch of other features such as Dynamic Data, and this short list of breaking changes. I...

Filters in ASP.NET MVC CodePlex Preview 4

In Preview 2 or Preview 3 of ASP.NET (I forget which), we introduced the concept of Action Filters. Sounds much more exciting than your run-of-the-mill LayOnTheCouchMunchingChipsWatchingInfomercialsFilter, that I originally proposed to the team. Thankfully, that was rejected. An action filter is an attribute you can slap on an action method in order to run some code before and after the action method executes. Typically, an action filter represents a cross-cutting concern to your action method. Output caching is a good example of a cross-cutting concern. In CodePlex Preview 4 of ASP.NET MVC, we split out our action filters...

An Arbitrary Cycle Method For ASP.NET MVC

In his Practical Review of ASP.NET MVC, Josh Charles provides a helpful review of ASP.NET MVC from a Rails developer’s perspective. It seemed fair and balanced, and the end result is that there’s room for improvement, which we’re taking to heart. However, that’s not the part that caught my attention. He mentioned that he wrote a cycle method but couldn’t write it as an extension method to HtmlHelper. this was an instance method that would take two strings and return the one that it didn’t return the last time it was called. In my templates,...

Hey Ma, I’m On TV!

Recently, Adam Kinney came by my office to interview me for a Channel 9 episode discussing ASP.NET MVC CodePlex Preview 4. I’ve known Adam for a long time, even before he joined Microsoft. I think we met (in person) at Tech-Ed 2003. In any case, we talk a bit about ASP.NET MVC and Preview 4, all the while I tried very hard not to put my foot in my mouth. At the end there are some outtakes of me impersonating Scott Hanselman doing an impersonation of Sean Conery. That wasn’t to make fun...

Super Simple MVC Ajax With JQuery Demo

UPDATE: I linked to the wrong post. I corrected the link. During the recent Insiders summit, Wally cornered me into recording a really short video demonstrating a feature of ASP.NET MVC. I decided to sprinkle a little Ajax in my demo by showing how to use jQuery to call an action that returns a JsonResult. Specifically, I show how to update a couple of regions in the page (two dom elements) with data pulled from the server. I then add a little sparkle to the demo by implementing the ubiquitous yellow fade when adding the content to the...

IronRuby With ASP.NET MVC Working Prototype

UPDATE 02.17.2009: I posted about a newer version of this prototype for ASP.NET MVC RC Update: I updated the source today. It now has minimal support for layouts. It needs more improvement for sure. In June, John Lam wrote about a demo he gave at Tech-Ed 2008 where he showed IronRuby running on ASP.NET MVC. He posted the code for the demo online, but it relied on an unreleased version of MVC, so the code didn’t actually work. Now that Preview 4 is out, I revisited the prototype and got it working again. I use the term working...

Notes on ASP.NET MVC CodePlex Preview 4

(If you want to skip all the blah blah blah, go straight to the release) What I love about working with The Gu (aka ScottGu, the man with many aliases) is that he makes my life easier with his gargantuan and detailed blog posts covering the features of each release. This allows me to follow up and fill in some details with a much shorter post, as by the time we get a release out the door, I’m usually too exhausted to write such a detailed post as he does. Yeah, excuses excuses. In his latest post, Scott...

Make Routing Ignore Requests For A File Extension

By default, ASP.NET Routing ignores requests for files that do not exist on disk. I explained the reason for this in a previous post on upcoming routing changes. Long story short, we didn’t want routing to attempt to route requests for static files such as images. Unfortunately, this caused us a headache when we remembered that many features of ASP.NET make requests for .axd files which do not exist on disk. To fix this, we included a new extension method on RouteCollection, IgnoreRoute, that creates a Route mapped to the StopRoutingHandler route handler (class that implements IRouteHandler). Effectively,...

User Input In Sheep’s Clothing

We all know that it is bad bad bad to trust user input. I don’t care if your users are all ascetic monks in a remote monastery, do not trust their input. However, user input often likes to put on sheep’s clothing and disguise itself as something else entirely, such as the case with ViewState. Another example of this is highlighted in the latest entry of his excellent series of ASP.NET MVC tips. In this post, Stephen Walther writes about how cookie values and server variables can be passed as parameters to action methods. Immediately, commenters understably asked...

Security Tip: Blocking Access to ASP.NET MVC Views Using Alternative View Engines

When you create a new ASP.NET MVC project using our default templates, one of the things you might notice is that there is a web.config file within the Views directory. This file is there specifically to block direct access to a view. Let’s look at the relevant sections. For IIS 6 (and Cassini) <add path="*.aspx" verb="*" type="System.Web.HttpNotFoundHandler"/> For IIS 7 <add name="BlockViewHandler" path="*.aspx" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/> What these sections do is block all access to any file with the .aspx extension...

Delegating Decorators

When approaching an extensibility model, I often find cases in which I want to merely tweak the existing behavior of the default implementation and wish I didn’t have to create a whole new specific type to do so. Instead of creating a specific type, I tend to write a decorator class that implements the interface and takes in both the default instance of that interface and a delegate (specified using a lambda of course). Let’s look at a quick example to make all this abstract talk more concrete. I’m playing around with the NVelocity View Engine for ASP.NET...

Everything You Wanted To Know About MVC and MVP But Were Afraid To Ask

Or, as my recent inbox tells me, you’re not afraid to ask. ;) A coworker recently asked for some good resources on getting up to speed on the Model View Controller (MVC) pattern. Around the same time, I received another email talking about how people are confused around the difference between MVC and the Model View Presenter (MVP) pattern. No better opportunity to apply the DRY principle by answering some of these questions with a blog post. MVC The first place to start digging into the MVC pattern is to look at the Wikipedia entry. That’ll...

IronRuby and ASP.NET BFFs Forever

UPDATE: I just posted the working demo here. I wish I could have been there, but I was celebrating my son’s first birthday (which gives me an opening to gratuitously post a picture of the kid here). I’m talking about Tech-Ed 2008 Orlando of course where John Lam presented a demo of IronRuby running on top of ASP.NET MVC. This demo builds on prototype work I’ve done with defining ASP.NET MVC routes and views using IronRuby. The final missing piece was defining controllers using IronRuby. Working with members of John’s team, Levi (a dev...

ASP.NET MVC And Dynamic Data Learn To Play Well Together

My compadre Scott Hunter, another PM on the ASP.NET team, who happens to work on the Dynamic Data feature, recently put together an example of using ASP.NET MVC and Dynamic Data Web Forms together in the same application. Look for the link to MvcDynamicData.zip on this Code Gallery page. I’ve been working on a post detailing a couple different ways to integrate WebForms and MVC, but life has been really busy for me lately. Hopefully I’ll get that to you soon. In the meanwhile, you can probably learn all you need to know by looking at this...

Updated Routing With WebForms

A while back I wrote a sample that demonstrated how to use Routing with WebForms. If you missed it, you can download the code here With the recent announcement that Routing will be included with .NET 3.5 SP1, you can see why I wanted to put that demo together. I have since updated that sample to work with the versions of Routing that comes with the April CodePlex build of MVC. This should also work with the SP1 Beta. I’ll verify that when I get a moment. As part of this update, I added a new...

.NET 3.5 SP1 Beta and Its Effect on MVC

The news is out, the beta for the Visual Studio 2008 and the .NET Framework 3.5 Service Pack has been released. As it relates to ASP.NET MVC, there are two important points to notice about the SP1 release: ASP.NET MVC is not included URL Routing is included Now you can see why there’s been so much focus on Routing from the MVC team, as Routing is now part of the Framework and is not out-of-band. This meant that we had to put a lot more effort into Routing to make sure it was...

Delegating Action Result

In my last post, I walked through a simple example of an ActionResult that you can use to transmit a file to the user’s browser along with a download prompt. The MVC framework will include several useful action results for common tasks. However, we might not cover all results you might want to return. In this post, I walk through a simple result that will cover all remaining cases. With the DelegatingResult, you simply pass it a delegate. This provides ultimate control. Let’s see it in action. public ActionResult Hello()...

Writing A Custom File Download Action Result For ASP.NET MVC

NEW UPDATE: There is no longer need for this custom ActionResult because ASP.NET MVC now includes one in the box. UPDATE: I’ve updated the sample to include a new lambda based action result. This also fixes an issue with the original download in which I included the wrong assembly. The April CodePlex source drop of ASP.NET MVC introduces the concept of returning an ActionResult instance from action methods. ScottGu wrote about this change on his blog. In this post, I’ll walk through building a custom action result for downloading files. As you’ll see, they are extremely easy to...

RouteEvaluator For Unit Testing Routes

A while back I wrote a routing debugger which is useful for testing your routes and seeing which routes would match a given URL. Rob suggested we have something like this for unit tests, so I whipped something simple up. This is a class that allows you to test multiple different URLs quickly. You simply create the RouteEvaluator giving it a collection of routes and then GetMatches which returns a List<RouteData> containing a RouteData instance for every route that matches, not just the first one. Here's a sample of usage. [Test] public void CanMatchUsingRouteEvaluator() { var routes = new RouteCollection(); GlobalApplication.RegisterRoutes(routes); var...

Code Based Repeater for ASP.NET MVC

Not long ago, my compadre Scott Hanselman related the following story... In a recent MVC design meeting someone said something like "we’ll need a Repeater control" and a powerful and very technical boss-type said: "We’ve got a repeater control, it’s called a foreach loop." I beg to differ. I think we can do better than a foreach loop. A foreach loop doesn’t help you handle alternating items, for example. My response to this story is, “The foreach loop is not our repeater control. Our repeater control is an iterating extension...

Anatomy of a "Small" Software Design Change

File this one away for the next time your boss comes in and asks, Yeaaah, I’m going to need you to make that little change to the code. It’ll only take you a couple hours, right? Software has this deceptive property in which some changes that seem quite big and challenging to the layman end up being quite trivial, while other changes that seem quite trivial, end up requiring a lot of thought, care, and work. Often, little changes add up to a lot. I’m going to walk through a change we made that seemed like a no-brainer but ended up having a...

Defining ASP.NET MVC Routes and Views in IronRuby

In a recent post I expressed a few thoughts on using a DSL instead of an XML config file. I followed that up with a technical look at monkey patching CLR objects using IronRuby, which explores a tiny bit of interop. These posts were precursors to this post in which I apply these ideas to an implementation that allows me to define ASP.NET MVC Routes using IronRuby. Also included in this download is an incomplete implementation of an IronRuby view engine. I haven't yet implemented layouts. IronRubyMvcDemo.zip Download (4.93 MB) This implementation works with the latest CodePlex...

ASP.NET MVC Preview of a Preview

UPDATE: Just to prove that this is a preview of a preview, we had a signing problem with the initial pre-built VSI download. If you tried building from source, everything should’ve been ok. We apologize for that. Even though this is meant to be a rough preview, we do want to have a high quality bar in that you should be able to try out the code. So if you run into that problem, please do download the VSI again. It’s no secret that Microsoft can get better at naming non RTM (Release to Manufacturing) releases. We have terms like CTP,...

Upcoming Changes In Routing

Made a few corrections on having default.aspx in the root due to a minor bug we just found. Isn’t preview code so much fun? We’ve been making some changes to routing to make it more powerful and useful. But as Uncle Ben says, with more power comes more responsibility. I’ll list out the changes first and then discuss some of the implication of the changes. Routes no longer treat the . character as a separator. Currently, routes treat the . and / characters as special. They are separator characters. The upcoming release of routing will only treat the...

My First IronRuby Unit Test Spec For ASP.NET MVC

Way down the road, it would be nice to be able to build ASP.NET MVC applications using a DLR language such as IronRuby. However, enabling DLR language support isn’t free. There are going to be places in our design that are specific to statically typed languages (such as Attribute based filters) that just wouldn’t work (or would be too unnatural) with a dynamic language. Ideally we can minimize those cases, and for the ones we can’t, we need to make sure the extensibility of the framework allows for extending the system in such a way that we can provide a DLR friendly...

A Few Notes About The MVC CodePlex Source Code Release

Whew! I’ve held off writing about MVC until I could write a non-MVC post in response to some constructive criticism (It’s not just Sean, Jeff mentioned something to me as well). Now that I’ve posted that, perhaps I’ve bought myself a few MVC related posts in a row before the goodwill runs dry and I have to write something decidedly not MVC related again. ;) As ScottGu recently posted, the ASP.NET MVC source code is now available via CodePlex. A move like this isn’t as simple as flipping a switch and *boom* it happens. No, it takes a lot...

ASP.NET Routing Debugger

In Scott Hanselman’s wonderful talk at Mix, he demonstrated a simple little route tester I quickly put together. This utility displays the route data pulled from the request of the current request in the address bar. So you can type in various URLs in the address bar to see which route matches. At the bottom, it shows a list of all defined routes in your application. This allows you to see which of your routes would match the current URL. The reason this is useful is sometimes you expect one route to match, but another higher up the stack matches instead....

Using Routing With WebForms

UPDATE: I updated the sample to work with the final version of ASP.NET Routing included with ASP.NET 3.5 SP1. This sample is now being hosted on CodePlex. Download the demo here In my last post I described how Routing no longer has any dependency on MVC. The natural question I’ve been asked upon hearing that is “Can I use it with Web Forms?” to which I answer “You sure can, but very carefully.” Being on the inside, I’ve had a working example of this for a while now based on early access to the bits. Even so, Chris Cavanagh impressively beats me to...

Thoughts on ASP.NET MVC Preview 2 and Beyond

At this year’s Mix conference, we announced the availability of the second preview for ASP.NET MVC which you can download from here. Videos highlighting MVC are also available. Now that I am back from Mix and have time to breathe, I thought I’d share a few (non-exhaustive) highlights of this release as well as my thoughts on the future. New Assemblies and Routing Much of the effort and focus of this release was put into routing. If you’ve installed the release, you’ll notice that MVC has been factored into three assemblies: ...

Abstract Base Classes Have Versioning Problems Too

This is part 2 in an ongoing series in which I talk about various design and versioning issues as they relate to Abstract Base Classes (ABC), Interfaces, and Framework design. In part 1 I discussed some ways in which ABCs are more resilient to versioning than interfaces. I haven’t covered the full story yet and will address some great points raised in the comments. In this part, I want to point out some cases in which Abstract Base Classes fail in versioning. In my last post, I mentioned you could simply add new methods to an Abstract Base Class and not...

ASP.NET MVC Update

By the way my blogging frequency has declined, you can guess I’ve been quite busy here at Microsoft preparing for the next release of ASP.NET MVC. It’s not just working on specs, design meetings, etc... that keep me busy. It’s preparing for several talks, various spec reviews, building hands on labs, demo and and app building, etc...that keeps me busy. All the while I am still learning the ropes and dealing with selling a house in L.A. and buying a house up here. There’s a lot that goes into being a PM I naively didn’t expect, on top...

Blocking Direct Access To Views in ASP.NET MVC

UPDATE: I improved this based on some feedback in my comments. With ASP.NET MVC it is possible for someone to try and navigate directly to a .aspx view. In general, this only leaves them with an ugly error message as Views typically need ViewData in order to work. However, one approach that I think will easily work is to create a Web.config file in the root of your Views directory that contains the following. We need to do more testing on our side to make sure there's no pathological case in doing this, but so far in my personal testing, it seems to...

So A Model, A View, and a Controller Walk Into a Bar

At the risk of embarrassing myself and eliciting more groans, I am going to share a joke I made up for my Code Camp talk. I was inspired to come up with some humor based on Jeff’s Sesame Street Presentation Rule post. I fully understand his post was addressing something deeper than simply telling a gratuitous joke in the presentation. The context is that I just finished explaining the various dependencies between the Model, View, and Controller within the MVC pattern. UPDATE: Updating this joke as the feedback comes in. The original is at the bottom. So a Model, a View, and a...

Come Work With Me And Other Great People

The ASP.NET and Silverlight team are hiring! Brad Abrams (who happens to be my “grand-boss” as in my boss's boss) posted a developers wanted ad on his blog: Are you JavaScript guru who has a passion to make Ajax easier for the masses? Are you the resident expert in ASP.NET and consistently think about how data driven applications could be easier to build? Are you a TDD or patterns wonk that sees how ASP.NET MVC is a game-changer? Are you excited about the potential of...

Seattle Code Camp Wrapup

The Seattle Code Camp (which despite the misleading photo, isn’t a camping trip) is now over and I have nothing but good things to say about it. I didn’t get a chance to see a lot of talks but did enjoy the xUnit.net talk by Jim Newkirk and Brad Wilson. I’m a fan of their approach to providing extensibility and this session provided all the impetus I needed to really give xUnit.net a try rather than simply talking about trying it. :) As for my own talk, I had the great pleasure of showing up late to my talk. To...

ASP.NET MVC Helpers For Repopulating A Form

A common pattern when submitting a form in ASP.NET MVC is to post the form data to an action which performs some operation and then redirects to another action afterwards. The only problem is, the form data is not repopulated automatically after a redirect. Let's look at remedying that, shall we? When submitting form data, the ASP.NET MVC Toolkit includes a helper extension method that makes it easy to go the other direction, populating an object from the request. Check out the following simplified controller action adapted from an example ScottGu’s post on handling form data. [ControllerAction] public void Create() { Article article...

Testing Routes In ASP.NET MVC

The ASP.NET Routing engine used by ASP.NET MVC plays a very important role. Routes map incoming requests for URLs to a Controller and Action. They also are used to construct an URL to a Controller/Action. In this way, they provide a two-way mapping between URLs and controller actions. When building routes, it may be useful to write unit tests for the routes to ensure that you’ve set up the proper mappings you intend. ScottGu touched a bit on unit testing routes in part 2 of his series on MVC in which he covers URL Routing. In this post,...

Interview with me on the ASP.NET Podcast Show

Yesterday, Wally McClure interviewed me for the ASP.NET Podcast Show. We chatted for around half an hour on my background, Microsoft, and ASP.NET MVC. It was a fun chat, but I have to warn you, I was very sleep deprived (a constant condition lately), so at points I tend to ramble a bit, second-guess myself (I was right the first time, model-view-thing-editor!), and even contradict myself. I’m not normally that harebrained. I promise. Ok, maybe just a little. With all those caveats in place, give it a listen. This is why writing a blog is so much easier than being interviewed. All the...

Thank You For Helping Me With My Job With ASP.NET MVC

I have a set of little demos apps I’ve been working on that I want to release to the public. I need to clean them up a bit (you’d be surprised how much I swear in comments) and make sure they work with the CTP. Hopefully I will publish them on my blog over the next few weeks. In the meanwhile, there’s some great stuff being posted by the community I want to call out. All these great posts are making my life easier. Routing Revisited - Sean Lynch talks about some interesting route scenarios. Currently the Route...

ASP.NET MVC Design Philosophy

Eilon Lipton, the lead developer on the ASP.NET MVC project shares some of his thoughts on the design philosophy guiding the shaping of the framework. There have been many post describing what the framework is and how to perform tasks, which are really useful. I think a more reflective post like this is a breath of fresh air and a nice insight into how the team is making decisions. Eilon also covers some of the lessons we’ve already learned in building the CTP, and some of the changes we have planned for the next CTP. At the end he lists some interesting...

Using ASP.NET MVC With Visual Web Developer Express

UPDATE: ASP.NET MVC now works with Visual Web Developer Express SP1 Some developers who downloaded the ASP.NET Extensions CTP specifically for ASP.NET MVC and then opened up Visual Web Developer like it was Christmas morning instead got a lump of coal. We currently only include Web Application Projects for ASP.NET MVC, which Visual Web Developer does not support. I was planning to write up a post on this, but Scott Koon beat me to it. And thank goodness! I’m busy enough as it is already. It’s all part of my master plan to have members of the community doing my job for...

Writing Unit Tests For Controller Actions

UPDATE: Completely ignore the contents of this post. All of this is out-dated. Test specific subclasses are no longer necessary with ASP.NET MVC since our April CodePlex refresh Just a brief note on writing unit tests for controller actions. When your action has a call to RedirectToAction or RenderView (yeah, pretty much every action) be aware that these methods have dependencies on various context objects. If you attempt to mock these objects, you sometimes also have to mock their dependencies and their dependencies' dependencies and so on, depending on what you are trying to test. This is why...

Extending ASP.NET MVC To Add Conventions

UPDATE: Much of this post is out-of-date with the latest versions of MVC. We long sinced removed the ControllerAction attribute. Note: If you hate reading and just want the code, it is at the bottom. Eons ago, I was a youngster living in Spain watching my Saturday morning cartoons when my dad walked in bearing freshly made taquitos and a small cup of green stuff. The taquitos looked delicious, but I was appalled at the green stuff. Was this some kind of joke? My dad wanted me to simply just taste it but I refused because I absolutely knew it would suck...

The REST-Like Aspect Of ASP.NET MVC

While at DevConnections/OpenForce, I had some great conversations with various people on the topic of ASP.NET MVC. While many expressed their excitement about the framework and asked when they could see the bits (soon, I promise), there were several who had mixed feelings about it. I relish these conversations because it helps highlight the areas in which we need to put more work in and helps me become a better communicator about it. One thing I’ve noticed is that most of my conversations focused too much on the MVC part of the equation. Dino Esposito (who I met very briefly), wrote...

Rhino Mocks + Extension Methods + MVC == Crazy Delicious

UPDATE: This content is a bit outdated as these interfaces have changed in ASP.NET MVC since the writing of this post. One task that I relish as a PM on the ASP.NET MVC project is to build code samples and sample applications to put the platform through its paces and try to suss out any problems with the design or usability of the API. Since testability is a key goal of this framework, I’ve been trying to apply a Test Driven Development (TDD) approach as I build out the sample applications. This has led to some fun discoveries in terms of using...