ASP.NET 4.0 Awesomeness

BackDraft

ASP.NET 4.0 Awesomeness

By Jonathan Goodyear

I love springtime. The newness of everything gets you motivated to do great things. Speaking of new, Visual Studio 10 Beta 1 has been released to us folks who have signed NDAs; by the time you read this, you may even be able to download it yourself. I must say I am pretty impressed with everything that it has to offer. As per usual with betas of Visual Studio, it is a bit sluggish (especially with the new WPF UI), but that will improve as RTM approaches.

In this column, I m going to focus on the first batch of new ASP.NET 4.0 features that struck me as interesting and relevant. And no, this information doesn t violate my NDA. Silly reader.

One of the most commonly used ASP.NET features is output caching. It is an ideal way to avoid taking the hit for expensive operations on commonly viewed web pages. Unfortunately, high-volume websites that have a lot of content can quickly run out of memory, even with servers that have considerable resources. ASP.NET 4.0 introduces an extensible caching model that allows you to create your own caching provider to store cached pages in any location or fashion you prefer. Not only that, different pages can be cached in different ways, so you could (for instance) cache the most commonly used pages in memory, while caching other content on an external disk (so that web farms can share cached content).

Speaking of memory, another commonly used aspect of ASP.NET that can consume a lot of resources is Session State. ASP.NET 4.0 combats this by introducing a feature that allows you to compress your Session State using the System.IO.Compression.GZipStream .NET Framework library, dramatically reducing the amount of space required to store each session. This may help you stave off having to store Session in SQL Server, which would introduce a performance hit.

A new little feature that is bigger than it first appears is Permanent Redirection. A call to Response.RedirectPermanent redirects a web request at the server. This saves an extra hop that is usually required with normal calls to Response.Redirect that require a round trip to the client. The nicest part about this, however, is that Response.RedirectPermanent returns a 301 Moved Permanently response to the client instead of the 302 Found response that is normally returned. This will help search engines and other websites that link to your websites update their links more quickly and efficiently.

Routing for Web Forms is another great feature to help your users get where they need to go. Introduced alongside the ASP.NET MVC Framework when .NET 3.5 SP1 was released, Routing enables you to create friendly URLs that don t map to physical files on the server. The Routing engine maps the friendly URLs to their physical counterparts. For instance:

     http://yoursite.com/products/kitchen/flatware/

would map to a page like this:

     http://yoursite.com/product.aspx?cat=kitchen&productline=flatware

You currently can make Routing work with Web Forms, but ASP.NET 4.0 makes the process much easier. You also now get access to the route data in the code-behind, markup, and DataSource Control parameters via the Page.RouteData.Values collection.

There are some interesting new features for the client, as well. For instance, the Page class now has Keywords and Description properties that allow you to set their respective meta tags on the page. You also can set them in the @Page directive. You also can take more granular control over ViewState for controls, allowing you to set their status to Enabled, Disabled, or Inherit (which will grab its ViewState settings from its containing control).

Developers who need to use a lot of JavaScript will appreciate the new feature that allows you to have a hand in determining the Client IDs assigned to ASP.NET controls on the page. This is set via the ClientIdMode property of the @Page directive. Note that with power comes responsibility. You can get into trouble because one of the options puts you in total control and does not validate that you are creating valid IDs or non-duplicate IDs.

There is a host of new AJAXy stuff in ASP.NET 4.0, as well as one- and two-way databinding in JavaScript. We ll talk more about those things in a future column. I am very happy and impressed that Microsoft continues to find new ways to help us develop web applications faster and easier, while still giving us options to take control of the process where we deem necessary. That last part is where previous attempts by Microsoft (e.g., Visual Basic 6 and previous) became frustrating. Visual Studio s decade version is poised to ensure that Microsoft remains the world leader in software development tools, and ASP.NET will remain the world s most powerful and versatile web development platform.

Jonathan Goodyear ([email protected]) is president of ASPSOFT, an Internet consulting firm in Orlando, FL. Jonathan is Microsoft Regional Director for Florida, an ASP.NET MVP, a Microsoft Certified Solution Developer, and a contributing editor for asp.netPRO.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish