I do appreciate working directly on the latest ASP.NET MVC technology these days for actual money. Extreme penny pinchers use Microsoft technology and these cheapskates tend to stay behind the latest stuff‚ÄĒin my experience over eight years behind. With this great opportunity comes great responsibility. So, today, let‚Äôs try to see how well a developer with salt-and-pepper hair can respond to what the kids are pounding out in Redmond:
One incorrect assumption I made when looking at ASP.NET MVC was the pessimistic view that the classic Web Forms crowd would jealously stand still. Yes, the release of ASP.NET 4 would be some sad competitive crap that would childishly ignore what the MVC team was doing. My assumption was wrong. Dan Maharry‚Äôs ‚ÄúASP.NET 4.0 Part 12, Routing Helper Functions‚ÄĚ:
With our routes defined, we can now set up hyperlinks between routes. All we need are the name of the route and the values of any route parameters. If we need to do it inline in the code (perhaps because it‚Äôs part of a data-binding operation) we can use the new
One (me) could make the mistake that since the ASP.NET Page Life Cycle Overview as described by MSDN appears to not have changed (much) for years, this appearance of Routing (from the MVC world) could easily be overlooked as Routing is plugged in higher in the stack, above the ASP.NET ‚ÄúPage‚ÄĚ concept (it‚Äôs an HTTP Module). Better than this MSDN piece is the award-winning CodeProject.com article, ‚ÄúASP.NET Application and Page Life Cycle‚ÄĚ by Shivprasad koirala (see also: ‚ÄúWhat is the ‚Äėpage lifecycle‚Äô of an ASP.NET MVC page, compared to ASP.NET WebForms?‚ÄĚ from StackOverflow.com). In attempt to not overlook here, one has this: ‚ÄúWhat‚Äôs New in ASP.NET 4 and Visual Web Developer‚ÄĚ‚ÄĒand this: ‚ÄúURL Routing with ASP.NET 4.0‚ÄĚ by Brij.
One terrible way to approach ASP.NET MVC for the first time is to be the guy that is ‚ÄúUsing WebControls In ASP.NET MVC Views.‚ÄĚ Having this very thoughtful article in my personal notes show my careful consideration for MVC beginners coming from the world of Web Forms, tempted by ‚Äúthe obvious.‚ÄĚ
This MSDN article, ‚ÄúEvents in ASP.NET Master and Content Pages,‚ÄĚ lists no less than 17 events for ASP.NET master pages. This list clearly applies to Web Forms as any ‚Äúcontrol loading‚ÄĚ events should not exist in ASP.NET MVC (but they do).
I need to form the habit of regularly reviewing the System.Web.UI.HtmlControls Namespace. New controls, like
HtmlLink, have been added since ASP.NET 2.0. Also, knowing how the
Control.ClientID property works is also futuristic in ASP.NET land (actually, the knowing the role of
ClientIDMode is the key here).
What should make ASP.NET look super cool to any developer that likes to write code is what Rob Conery writes about in ‚ÄúASP.NET MVC: Securing Your Controller Actions‚ÄĚ:
ASP.NET MVC Preview 2 introduces the new
ActionFilterAttribute, which allows you to declare ‚ÄúFilter Attributes‚ÄĚ for the actions on your controller. Think of these things, in essence, as
OnLoadevents‚ÄĒa bit of code that’s executed before or after your Action.
This use of attributes for a Web application goes farther, one can see this in ‚Äúis [AcceptVerbs(HttpVerbs.Post)] deprecated or to be deprecated in ASP.NET MVC 2 or later?‚ÄĚ:
No, it‚Äôs not deprecated, and it won’t be, because
[AcceptVerbs]is the only way to decorate a method that accepts several (but not all) verbs.
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Put)]
It‚Äôs also the only way you can specify a verb that‚Äôs not one of the ‚Äúcore four‚ÄĚ, such as those which are part of WebDAV:
Matt Hawley shows me that the use of attributes make secure patterns like the ‚ÄúASP.NET MVC‚ÄĒUsing Post, Redirect, Get Pattern‚ÄĚ possible.
Finally, this article, ‚ÄúIntegrating Silverlight and ASP.NET MVC,‚ÄĚ by Tim Heuer gets me back into triple-threat mode by using JSON (with
DataContractSerializer) from ASP.NET MVC to be consumed as POCOs:
Why not use
System.Jsonand LINQ to JSON? You could absolutely. In doing so you could use your LINQ skills and get the data out of the Json stream and put it into a new object. You‚Äôll still have to create a local class representation because Silverlight can‚Äôt bind to an anonymous type. This is the first reason I like just using the serializer. The second reason is size. I don‚Äôt know why I‚Äôm so picky, but I am. Using the
DataContractSerializermethod here, my app is about 7K. Adding a reference to
System.Jsonand using those methods, my app is 27K. For me, there is no additional benefit in code for what I‚Äôm doing to add that extra size, so I choose not to. But you can‚Ä¶absolutely. Your application needs may be different and the size cost/benefit analysis may result in a different outcome than mine‚Ä¶but there, I‚Äôve stated my reasons here.
My triple-threat (my ‚Äúgrand unified user interface‚ÄĚ), by the way, means to be ASP.NET MVC, WPF and Silverlight: