ASP.NET 4 Unleashed: An Interview with Kevin Hoffman and Nate Dudek
ASP.NET has been around since January of 2002 and has since improved drastically with each release. With each release comes a new set of controls, new server and client functionality, and sometimes even new paradigms that enable you as a developer to be more productive. ASP.NET 4 Unleashed by industry experts Kevin Hoffman and Nate Dudek is a treasure chest of knowledge for the fourth iteration of the well known framework.
I have been working with ASP.NET for close to four years at A.J. Boggs & Company. When I found out I had the privilege to interview ASP.NET experts Kevin and Nate I decided to ask them some in depth questions about their book, the ASP.NET Framework in general and the future of web development.
Eric Vogel: Who would you say is the target audience for ASP.NET 4 Unleashed, and do you feel you hit your mark?
Nate Dudek: Developers of all levels will get something out of ASP.NET 4 Unleashed. The early chapters of the book start at the very beginning—installing ASP.NET and getting comfortable with Visual Studio 2010—and lets novice developers get their feet wet by building small websites and walking through all of the different controls. In the later chapters, you’ll find more advanced concepts such as data paging, writing custom providers, AJAX, and new features such as Dynamic Data. There’s something for everyone.
Eric: If you are currently using ASP.NET 2.0 or 3.5, what is the main motivating factor to upgrade to ASP.NET 4.0?
Nate: For applications that are actively being developed or updated, there are some clear advantages to upgrading to .NET 4. First of all, Visual Studio 2010 is by far the best version of the product yet. It’s fast, and the new editor, upgraded Intellisense, and new navigation features are fantastic. ASP.NET, specifically, the web.config files have been dramatically simplified and are much cleaner to read and maintain. There have also been a lot of changes related to producing cleaner and standards-compliant HTML and CSS. Many of the controls, such as the validation labels, no longer render inline CSS, which gives you better control over the styling of your site. Controls like the Menu and FormView also give you the option of disabling the HTML table that was previously always rendered. Features such as Routing are fantastic for search engine optimization. These types of changes allow developers to more easily build clean, standards-compliant websites.
Eric: What role do you think ASP.NET MVC has to play in the future of ASP.NET? Do you see it as more of a replacement or a complement to Web Forms?
Nate: ASP.NET MVC is definitely a complementary addition to the ASP.NET framework. Traditional ASP.NET WebForms development will continue to be strong, but MVC is a great choice for applications looking to do rapid or test-driven development. It also helps enforce a clean separation of concerns by design. For developers who have experience with Ruby on Rails or other languages, it will be a familiar pattern.
Eric: What is your general rule of thumb on using ViewState and ControlState for controls? Do you generally disable ViewState unless it is needed in order to reduce the page size?
Nate: ViewState is one of those things that has received a bad name over the years, mostly due to developer abuse. When used properly, it can be a great tool. What developers need to remember is that anything in the page ViewState will get rendered out in a hidden field in the client-side HTML, which results in a larger page. We’ve seen enterprise applications where huge datasets are explicitly placed in ViewState—in one case causing a page size of over 100MB! Needless to say, it didn’t perform very well. ViewState should definitely be disabled in the scenarios where it’s not used, and objects should almost never be explicitly placed in ViewState through code unless absolutely necessary. ASP.NET 4 includes a new property called “ViewStateMode” which enables developers to disable ViewState by default, and then selectively enable it on controls that require it. It’s a nice addition, since previously it was always enabled by default and disabling it was done on a control-by-control basis. GridViews and some of the third party controls out there tend to be ViewState hogs in certain scenarios, and it should always be optimized before pushing a page to a production application.
Eric: What is your take on the ASP.NET Update Panel? When do you favor using a client side AJAX library such as jQuery instead for AJAX requests?
Nate: When the UpdatePanel control was first introduced into the ASP.NET framework, AJAX and the rich web as we know it was just emerging. For developers who were comfortable with ASP.NET development, it was an incredibly easy way for them to introduce asynchronous requests into their applications in a way that they were used to. Now that we have rich, easy-to-use client side libraries such as jQuery, it’s much easier to implement almost any client-side you can think of using only JavaScript. Personally, I use jQuery for almost all of my AJAX requests. It’s cleaner in my opinion, and faster. But, for ASP.NET developers who aren’t as comfortable with JavaScript, the UpdatePanel is still a great option to rapidly introduce AJAX into applications in a way that’s still consistent and maintainable.
Eric: When would you recommend that someone start out with an ASP.NET Dynamic Data Web Application, and conversely, when would you recommend not using a Dynamic Data Web Application?
Nate: If you take a look at the basic needs of your application, and it boils down to mostly CRUD (Create, Retrieve, Update, Delete) functionality with validation, and most of the "work" of your application is in coming up with the UI on top of a pretty straightforward data model, then I think Dynamic Data web applications might be something you should look into and might get you to production super fast. Additionally, if you want to rapidly prototype a fully functioning web application, then dynamic data can also be helpful. Despite its name, you can slowly remove the implicit (dynamic) stuff and replace it with more robust UI features. It's hard to generalize, but if your application is more involved than just performing CRUD operations on data (e.g., your application works more like using UI to advance workflow than perform simple data manipulation), then dynamic data might actually hamstring your efforts. If you have a full-featured middle tier, are using a third party middleware product, or your app sits on top of services rather than direct data, these are all scenarios that diverge from dynamic data's target audience. That's not to say that DD can't be adapted to those environments, but often the work of adapting dynamic data to those environments is more than just going with a more traditional Web Forms or ASP.NET MVC approach.
Eric: There has been a lot of debate on whether to use LINQ to SQL or Entity Framework when deciding on an OR/M for an ASP.NET Web Application. In your book you focus on LINQ to SQL. Is there a reason you chose LINQ to SQL over Entity Framework to demonstrate?
Kevin Hofffman: Throughout the book LINQ to SQL is used instead of Entity Framework for the sake of simplicity. If the code I want to show is in the UI, but I need data for the demo, LINQ to SQL can give me that data in the fewest lines of code with the smallest amount of impedance between what my UI wants and what my database contains. It also satisfies a large number of problems that many of this book's readers either have now or might have tomorrow. That said, there are a lot of compelling arguments for using the Entity Framework as well. Entity Framework allows you to model entities at a higher level of abstraction than simple database tables. While I can achieve some distance from tables and columns in LINQ to SQL, Entity Framework allows me to do true domain-driven design (DDD). This entity model can be used to produce multi-purpose POCOs (Plain Old CLR Objects), self-tracking C# objects that can be used as DTOs (Domain/Data Transfer Objects), and finally, the Entity Framework's persistence medium is abstracted as well. This means that if I want to, I can have my entity model talk to an Oracle database. LINQ to SQL, as its name implies, works only on SQL databases. In general I usually suggest that for small projects (especially those that might qualify for an ASP.NET Dynamic Data front-end), LINQ to SQL is ideal. However, the bigger your data store and the more complicated your domain model, the more often I recommend Entity Framework.
Eric: The new QueryExtender control allows for easy filtering of sorting data in a declarative way. Are there any pitfalls that you have run into with the QueryExtender control?
Kevin: The only pitfalls I've seen with the QueryExtender are the same as those with using LINQ queries in your code that eventually become SQL queries. This happens with LINQ to SQL and Entity Framework. Developers unfamiliar with how LINQ queries become SQL queries can unintentionally write poorly performing queries that look perfectly fine in code (or as parameters to the QueryExtender control). A little caution and some time spent in SQL profiler watching the queries you execute before you go to production can go a long way here.
Eric: What are your thoughts on the URL routing additions to ASP.NET 4.0? Do you see it as an easy way to bridge the gap across Web Forms and MVC?
Kevin: I love the URL routing additions. I've always been a huge fan and proponent of RESTful architecture, and the URL routing additions allow both ASP.NET and ASP.NET MVC to provide web applications with a RESTful URL style. The URL routing additions are now a part of the core of ASP.NET and that's a good thing for everyone. That said, I don't think they are a way of bridging an imaginary gap between Web Forms and MVC. Web Forms and MVC are two different ways of building ASP.NET applications, each with their own benefits and drawbacks and each with appeal to a different type of developer or project. URL routing bridges the gap between Web Forms and MVC only in the same way that Xaml bridges the gap between Silverlight and WPF—URL routing is just a common tool available to both frameworks.
Eric: What features would you like to see implemented in ASP.NET 5.0?
Kevin: I would love to see tighter integration between ASP.NET's request handling engine and some of the new asynchronous/multi-threading features coming in C# 5.0. I also think that HTML5 is the future of the web (not Silverlight or Flash or Java), and I want to see ASP.NET 5 completely embrace this with controls, APIs, tooling, and samples that allow for seamless integration of HTML5's client-side networking and data-binding with ASP.NET's server components. For example, HTML5 has a WebSocket that can be used to deliver "push" data to code running client-side in a browser. It would be awesome if ASP.NET (as opposed to other third-party, mostly Java-based servers) could serve as a Comet/WebSocket server rather than today's only .NET alternative—the Silverlight/WCF Duplex polling channel.
Eric: As web developers, what excites you the most about what HTML5 will bring to the table in the near future?
Kevin: As mentioned in my answer to the ASP.NET 5 question, HTML5 has really exciting networking and data capabilities that, when combined with other client-side tools like jQuery and CSS, create the perfect storm for the most compelling in-browser application experiences we've seen so far. If it really does gain widespread traction as a standard, then we could have "just" HTML5/jQuery/CSS code that provides cross-platform desktop and mobile application experiences.
Eric: What do you feel distinguishes your book from the all the rest?
Kevin: I think the one thing you'll notice as soon as you pick it up (especially given its weight and page count) is how thorough this book is. It doesn't just give you an overview and then tell you to go look at other books for the detail. This is the biggest, most complete compendium of ASP.NET 4 information you're going to find in print anywhere. Not only that, but the people who wrote this book aren't just authors, we're developers and architects who spend all day (and most of our nights) knee-deep in ASP.NET code, so the book is filled with samples, tips, and practical sidebars that you might not find in other books that just repurpose MSDN, blogs, and other online documentation for print form.
Nate: ASP.NET 4 Unleashed is exhaustingly thorough. At just over 1900 pages, we feel like we crammed as much information as physically possible into a single book. It covers the entire framework, from control overviews to new features, basic configuration to advanced techniques—it makes a great page-by-page tutorial, but is just as good as a desktop reference for expert developers. It’s truly a one-stop shop for everything you may need to know to build, debug and deploy a fully featured application.
I would like to express my gratitude to Kevin Hoffman, Nate Dudek, and InformIT for providing me with the privilege to conduct this interview.