home forums resources search newsjoinmembers: 6056
Hiveminds Network: Joomla Wordpress Drupal Fireorb Flash Java PHP Ruby Windows Linux
windows | Sun, 2008-07-20 05:51  tags: , , , ,

This document describes changes that have been made to the ASP.NET MVC framework between the Preview 3 release and the current CodePlex Preview 4 release. It also describes changes that you must make in existing MVC applications to run with the new release. download.

What’s New

This section provides information about the new and changed features in this release.

New Simple Membership Features in the Default Project Template

Most Web applications require some form of user authentication. This release includes an AccountController class in the default project template that handles the following user actions:

  • Login
  • Logout
  • Register
  • Change password

The Web.config file in the default project template includes settings for the MembershipProvider class. This means that ASP.NET will automatically create a SQL Server Express Edition membership database when membership features are first accessed. You can transfer the SQL Server Express Edition database to SQL Server database, or you can modify the connection string in the Web.config file to point to an existing database that contains membership tables.

The default template also includes copies of Microsoft ASP.NET AJAX script files. We are continuing to work on an MVC version of the ScriptManager control; for example, we are making it easy to register scripts that are contained in embedded resources. However, these improvements are not included in this release.

New Filter Types for Authorization and Exception Handling

This release includes two new filter types: authorization filters and exception filters. Although action filters continue to be the most common filter type, we wanted to provide filters that could run before any and all action filters, no matter what the scope was for the filters. This can help prevent scenarios such as where an OutputCache filter runs before an Authorization filter, and thus circumvents authorization.

The following features have been added or changed to support the new filter 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 FilterAttribute base class. With the introduction of the new filter types, we introduced a new base class that is useful for any filter attribute.

New Output Cache Filter

The OutputCacheAttribute class is a new action filter that is used to cache the output of an action method by using the built-in ASP.NET output cache.

Note   In this release, setting the CacheProfile property for an output cache filter throws an exception in Medium trust. This issue will be addressed in a future release.

Changes for ASP.NET AJAX

The following AJAX helpers were added. They make use of a new AjaxOptions class that is used to specify options for asynchronous operations.

ActionLink. This r enders 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. This r enders 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.

We continue to work on enhancing the AJAX features for ASP.NET MVC. The features described here are preliminary versions of features that we expect to enhance in future releases.

Namespaces in Routes
In previous previews of ASP.NET MVC, the framework scanned all the types in an assembly in order to find controller implementations. However, this occasionally caused exceptions to be thrown when the framework reflected over a type that inherits from another type for which no assembly is loaded.
In this release, we provide a means to specify which namespaces to examine when the framework tries to load a controller type by using the DefaultNamespaces property of ControllerBuilder. The following example shows how to add namespaces for resolving controllers.

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"); // ...
}

You can also specify namespaces route by route. (In this release you cannot do this by using the MapRoute extension method.) The following example shows how to specify namespaces for a route.

var dataTokens = new RouteValueDictionary();
dataTokens.Add("namespaces", new HashSet<string>(
new string[] {
"MyApp.Blog.Controllers",
"MyApp.Forum.Controllers",
"MyApp.Controllers"
})); routes.Add(
new Route("ns/{controller}/{action}/{id}", new MvcRouteHandler()) {
Defaults = new RouteValueDictionary(new {
action = "Index",
id = (string)null
}),
DataTokens = dataTokens
});

New Interface for Enhanced Testability of TempData

In this release we improved testability by allowing you to use session cookies rather than session state. A new ITempDataProvider interface has been added. By default, controllers use the SessionStateTempDataProvider which uses session state, but it is now possible to implement other providers.

ActionInvoker Extensibility Improvements

New virtual methods have been added that allow you to extend the invoker in advanced scenarios. The new methods are listed in the following table.

Method

Notes

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.

ViewDataDictionary

We made a minor change to the ViewDataDictionary changing its indexer to be a normal indexer and adding an Eval method which evaluates the model.

MVC Futures

The ASP.NET MVC team builds prototypes for many features during the course of normal development. Some of these features might not be included in the RTM release. If not, they might be included in a future full release. We have moved many of these features into a separate MVC Futures project. You’ll notice that the project template contains and references an assembly named Microsoft.Web.Mvc.dll, which is the compiled form of the MVC Futures project.

Note that the ComponentController and the RenderComponent methods have been replaced with the RenderAction method that is defined in the MVC Futures project. RenderAction works against a normal controller rather than against a special ComponentController object.

For this release, the MVC Futures assembly (Microsoft.Web.Mvc.dll) is included in the project template, but in the Beta and RTM releases, this will not be the case.

Upgrading an Existing Preview3 Application to Preview 4 CodePlex Release

The information in this section describes the changes that you must make to modify an ASP.NET MVC application that was created with the Preview 3 release so that it works with the Preview 4 release.

Update the references to the following assemblies to point to the new Preview 4 versions of the assemblies:

System.Web.Abstractions

System.Web.Routing

System.Web.Mvc

By default, these assemblies are located in the following folder:

%ProgramFiles% \Microsoft ASP.NET\ASP.NET MVC CodePlex Preview 4

Due to slight changes in the action filter APIs, if you wrote any custom action filters, you might need to update your code to match the new signatures.

To take advantage of some of the template changes, you might want to copy the template changes into your own project.

Known Issues

Setting the CacheProfile property on an OutputCache filter throws an exception in Medium trust.

Please note that to use ASP.NET MVC with the express editions of Visual Studio 2008, you will need to install : Visual Studio 2008 Express Edition SP1 Beta . For more information on this, check out ScottGu’s blog
Download


Happy Publishing!

windows's picture
Join Hiveminds and link to your website or blog.
 
Bitrix Site manager - fast to create, easy to manage CMS Comparison Matrix
Put Your Site Here Developer Links
 

Newsletter

Get updates on Hiveminds services, articles and downloads by signing up for the newsletter.

Editor's choice

Some of the better articles, stories and tutorials found at Hiveminds.

Find more

Find more of Hiveminds articles, stories, tutorials and user comments by searching.




Picked links

Hand picked websites and articles from around the web that provide quality reading.