AreaRegistration Class


Provides a way to register one or more areas in an ASP.NET MVC application.

Namespace:   System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Inheritance Hierarchy



public abstract class AreaRegistration
public ref class AreaRegistration abstract 
type AreaRegistration = class end
Public MustInherit Class AreaRegistration


Name Description
System_CAPS_protmethod AreaRegistration()

Initializes a new instance of the AreaRegistration class.


Name Description
System_CAPS_pubproperty AreaName

Gets the name of the area to register.


Name Description
System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_protmethod Finalize()

(Inherited from Object.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodSystem_CAPS_static RegisterAllAreas()

Registers all areas in an ASP.NET MVC application.

System_CAPS_pubmethodSystem_CAPS_static RegisterAllAreas(Object)

Registers all areas in an ASP.NET MVC application by using the specified user-defined information.

System_CAPS_pubmethod RegisterArea(AreaRegistrationContext)

Registers an area in an ASP.NET MVC application using the specified area's context information.

System_CAPS_pubmethod ToString()

(Inherited from Object.)


When you add an area to an ASP.NET MVC application, Visual Studio creates a file named AreaRegistration. The file contains a class that derives from AreaRegistration. This class defines the AreaName property and the RegisterArea method, which registers the route information for the new area.

The following example shows the AreaRegistration class created for a new area named Blog.

public class BlogAreaRegistration : AreaRegistration
    public override string AreaName
            return "Blog";

    public override void RegisterArea(AreaRegistrationContext context)
            new { action = "Index", id = "" }
Public Class BlogAreaRegistration
    Inherits AreaRegistration

    Public Overrides ReadOnly Property AreaName() As String
            Return "Blog"
        End Get
    End Property

    Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext)
        context.MapRoute( _
            "Blog_default", _
           "Blog/{controller}/{action}/{id}", _
            New With {.action = "Index", .id = ""} _
    End Sub
End Class

The Global.asax file contains the RegisterRoutes method that is called when an ASP.NET MVC application starts. The RegisterRoutes method of any application that implements areas must contain a call to the RegisterAllAreas method.

The following example shows a RegisterRoutes method that contains a call to RegisterAllAreas.

public static void RegisterRoutes(RouteCollection routes)
        "Default",                      // Route name
        "{controller}/{action}/{id}",   // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
[Visual Basic]
Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.MapRoute( _
        "Default", _
        "{controller}/{action}/{id}", _
        New With {.controller = "Home", .action = "Index", .id = ""} _

End Sub

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

System.Web.Mvc Namespace

Return to top