BT

Microsoft Releases ASP.NET MVC Framework Preview 4

| by Robert Bazinet Follow 0 Followers on Jul 17, 2008. Estimated reading time: 3 minutes |

In keeping with its releases of about once a month, Microsoft has released Preview 4 the ASP.NET MVC Framework.  This release promises to start giving developers more higher level features aiding in better productivity.

Scott Guthrie eluded to the release in a blog post from earlier in the week where he explains some of the new features titled, ASP.NET MVC Preview 4 Release (Part 1).

What's New

New Simple Membership Features in the Default Project Template

An AccountController class in included in the default project template handling user actions for the following:

  • Login
  • Logout
  • Register
  • Change Password

Considering most applications deal with users and the ability to authenticate them, this addition saves time for developers.   The default settings for the MembershipProvider in this case uses SQL Server Express Edition but can be made to with SQL Server or some existing database.

New Filter Types for Authorization and Exception Handling

This release includes two new filter types, authorization and exception filters.  These filters are designed to run before any other action filters, regardless of the scope of other filters. 

Features that have been added to support these new types:

  • New IAuthorizationFilter and IExceptionFilter interfaces. Authorization filters are guaranteed to run before any action filters. Every exception filter is executed, even if a filter indicates that it has handled the request. This is useful for logging and handling exceptions.
  • AuthorizeAttribute class. This is the default concrete implementation of IAuthorizationFilter. It is used to secure action methods.
  • HandleErrorAttribute class. This is the default concrete implementation of IExceptionFilter. It is used to handle exceptions and to specify a view to render when an exception occurs.

New Output Cache Filter

Taking advantage of the existing an robust ASP.NET caching mechanism, the OutPutCacheAttribute is implemented to cache the output of an action method.

Changes for ASP.NET AJAX

A couple AJAX helpers were added which use the AjaxOptions class used for asynchronous operations:

  • ActionLink -  Renders an anchor tag to an action method. When the link is clicked, the action method is invoked asynchronously. A typical use for this helper takes the response and updates a DOM element by specifying the AjaxOptions.UpdateTargetId property.
  • Form - Renders an HTML form that is submitted asynchronously. A typical use for this helper is to submit a form, and like the ActionLink, take the response and update a DOM element by specifying the AjaxOptions.UpdateTargetId property.

Scott Hanselman has good examples in an article on his blog demonstrating these features.

Namespaces in Routes

Previous versions of the framework had occasional issues with the method which it used to find controller implementations which led to an exception being thrown.  This release fixes those issues by using a DefaultNamespaces property on the ControllerBuilder.   An example of how this is implemented is:

void Application_Start(object sender, EventArgs e) 
{
ControllerBuilder.Current.DefaultNamespaces.Add("MyApp.Controllers");
ControllerBuilder.Current.DefaultNamespaces.Add("MyApp.Blog.Controllers");
ControllerBuilder.Current.DefaultNamespaces.Add("ThirdPartyApp.Controllers");

// ...
}

New Interface for Enhanced Testability of TempData

A new interface, ITempDataProvider has been introduced.  This allows controllers to use different providers other than the SessionStateTempDataProvider, making for improved testability allowing developers to use session cookies instead of session state. 

ActionInvoker Extensibility Improvements

Virtual methods have been added which extend the invoker when used in advanced instances.  The new methods include: 

  • GetFiltersForActionMethod - Returns all filters (authorization, action, and exception filters) for the action method.
  • InvokeActionResultWithFilters - Calls ExecuteResult on the ActionResult object that is returned from the action method, along with all the result filters that are applied to the action method.
  • InvokeAuthorizationFilters - Invokes the authorization filters that are applied to the action method.
  • InvokeExceptionFilters - Invokes the exception filters that are applied to the action method.

The preview is available on CodePlex where it can be downloaded now.  Be sure to review the Readme file that includes details of all the new features also available for download from CodePlex.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss
BT