ASP. net mvc CodePlex Preview 4 Release Notes
You can download this document from here: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx? ReleaseId = 15389.
Translation: Anders Liu
Abstract: This document describes the differences between Preview 3 of ASP. net mvc framework and current CodePlex Preview 4. We also introduced that to run a new version, you must modify the existing MVC application.
- Introduction
- What's New
- Simple member qualification features in the default Project template
- Filter Type Used for authorization and Exception Handling
- Output cache Filter
- Changes in ASP. NET AJAX
- Routing namespace
- Enhanced testability interface of TempData
- ActionInvoker scalability and Improvement
- ViewDataDictionary
- Future of MVC
- Upgrade the existing Preview3 application to Preview 4 CodePlex Release
- Known issues
Introduction
The release of CodePlex Preview 4 contains many new features and modifies the default Project template. The purpose of modifying the default Project template is to help start the most common application building scenarios. Many new features are concentrated in simple AJAX scenarios.
What's New
This section describes the new and modified features of the released version.
Simple member qualification features in the default Project template
Many Web applications require some form of user authentication. The released version contains an AccountController class in the default Project template to process the following user operations:
- Login
- Cancel
- Register
- Change Password
The Web. config file of the default Project template contains the configuration of the MembershipProvider class. This means that ASP. NET will automatically create an SQL Server Express Edition membership database when you first access the membership feature. You can convert an SQL Server Express Edition database to an SQL Server database, or modify the connection string in the Web. config file to point it to an existing database that contains a membership table.
The default template also contains a copy of the Microsoft ASP. net ajax script file. We have been constantly working on the MVC version of The ScriptManager control; for example, we make it easier to register scripts included in Embedded resources. However, these improvements are not included in this release.
Filter Type Used for authorization and Exception Handling
This release contains two new filter types: Authorization filter and exception filter. Although the action filter is still the most common filter type, we want to provide a filter that can run before any or all action filters, regardless of the scope of the filter. This prevents situations, such as executing the OutputCache filter before the Authorization filter, resulting in unauthorized Authorization.
To support new filter types, the following features are added or modified:
- The new IAuthorizationFilter and IExceptionFilter interfaces. The authorization filter can be run before all other operation filters. Each exception filter is executed, even if a filter indicates that it has processed the request. This helps record and handle exceptions.
- AuthorizeAttribute class. This is the default Implementation of IAuthorizationFilter. Used to ensure the security of operation methods.
- HandleErrorAttribute class. This is the default Implementation of IExceptionFilter. Used to handle exceptions and specify the view to be displayed when exceptions occur.
- The new FilterAttribute base class. We introduced a new base class together with the new filter type, which is useful for all filter features.
Output cache Filter
The OutputCacheAttribute class is a new operation filter used to cache the output of operation methods using the built-in ASP. NET output cache.
Note:
In this release, setting the CacheProfile attribute for the output cache filter at the Medium trust level throws an exception. This issue will be solved in future releases.
Changes in ASP. NET AJAX
Added the following AJAX auxiliary method. They use the AjaxOptions class to specify options for asynchronous operations.
- ActionLink. This method presents an anchor tag pointing to an operation method. When you click the link, the operation method is called asynchronously. A typical application of this auxiliary method is to obtain the response and update the DOM element by specifying the AjaxOptions. UpdateTargetId attribute.
- Form. This method presents an HTML form that can be submitted asynchronously. A typical application of this auxiliary method is to submit a form, which is similar to ActionLink. You can specify the AjaxOptions. UpdateTargetId attribute to obtain the response and update the DOM element.
We will continue to enhance AJAX features for ASP. net mvc. The feature mentioned here is only a preliminary version, and we hope to provide stronger features in future releases.
Routing namespace
In a browser version earlier than ASP. net mvc, the Framework scans all types in the Assembly to find the controller implementation. However, this occasionally throws an exception. If a type is inherited from a type in an assembly that has not yet been loaded, the framework will encounter an error when reflecting the type.
In this release, we provide a way to specify the namespace for the framework to check when trying to load the Controller type. This requires the controultnamespaces attribute of the ControllerBuilder class. The following example shows how to load a namespace for the resolution controller.
<Br/> void Application_Start (object sender, EventArgs e) {<br/> ControllerBuilder. current. defaultNamespaces. add ("MyApp. controllers "); <br/> ControllerBuilder. current. defaultNamespaces. add ("MyApp. blog. controllers "); <br/> ControllerBuilder. current. defaultNamespaces. add ("ThirdPartyApp. controllers "); <br/> //... <br/>}
You can also specify a namespace for each route in sequence. (You cannot use the MapRoute extension method in this release .) The following example shows how to specify a namespace for a route.
<Br/> var dataTokens = new RouteValueDictionary (); <br/> dataTokens. add ("namespaces", new HashSet <string> (<br/> new string [] {<br/> "MyApp. blog. controllers ", <br/>" MyApp. forum. controllers ", <br/>" MyApp. controllers "<br/>}); <br/> routes. add (<br/> new Route ("ns/{controller}/{action}/{id}", new MvcRouteHandler ()) {<br/> Defaults = new RouteValueDictionary (new {<br/> action = "Index", <br/> id = (string) null <br/> }), <br/> DataTokens = dataTokens <br/>}); <br/> </string>Enhanced testability interface of TempData
In this release, we have improved the testability. You can use session cookies instead of session statuses. Added a new ITempDataProvider interface. By default, the Controller accesses the session status through SessionStateTempDataProvider, but other providers can now be implemented.
ActionInvoker scalability and Improvement
A new virtual method is added. In advanced scenarios, you can extend the caller. The following table lists the new methods.
Method |
Description |
GetFiltersForActionMethod |
Returns all filters (authorization, operation, and exception filters) on the operation method ). |
InvokeActionResultWithFilters |
Call the ExecuteResult method on the ActionResult object returned by the operation method and all the result filters applied to the operation method. |
InvokeAuthorizationFilters |
Call the authorization Filter Applied to the operation method. |
InvokeExceptionFilters |
Call the exception filter applied to the operation method. |
ViewDataDictionary
We made a few changes to ViewDataDictionary, changed its indexer to a general indexer, and added the Eval method to evaluate the model.
Future of MVC
The ASP. net mvc team developed prototypes for many features during daily development. Some of these features will be included in the RTM release. If it is not included, it may be included in the future full release version. We put many of these features in a separate MVC ures project. You will notice that the Project template contains and references an Assembly named Microsoft. Web. Mvc. dll, which is the compilation form of the MVC Futures project.
Note that the ComponentController and RenderComponent methods have been replaced with the RenderAction method defined in the MVC Futures project. The RenderAction works with a common controller instead of a specific ComponentController object.
For this release, the MVC Futures assembly (Microsoft. Web. Mvc. dll) is included in the Project template, but not in Beta and RTM releases.
Upgrade the existing Preview3 application to Preview 4 CodePlex Release
This section describes how to modify an ASP. net mvc application created using Preview 3 release to run on Preview 4 release.
- Update the reference to the following Assembly to point it to the new Preview 4 assembly:
- System. Web. Category actions
- System. Web. Routing
- System. Web. Mvc
By default, the Assembly is located in the following folder:
% ProgramFiles % \ Microsoft ASP. NET \ ASP. net mvc CodePlex Preview 4
- Because the operation filter API has changed a little, if you write a custom operation filter, you need to update your code and match the new signature.
- To take advantage of some changes in the template, you may need to copy the changes to your project.
Known issues
- With Medium Trust, setting the CacheProfile attribute on the OutputCache filter throws an exception.
- Note if you want to use ASP. net mvc in Visual Studio 2008 quick build, you need to install Visual Studio 2008 Express Edition SP1, located at: http://www.microsoft.com/downloads/details.aspx? FamilyId = BDB6391C-05CA-4036-9154-6DF4F6DEBD14 & displaylang = en. For more information, refer to ScottGu's blog topic: Workshop.