0

I am working in a Web Site Project (not Web Application) where Web Forms and MVC happily live together. To organize my code, I'm trying to setup Areas with the MVC part and am running into this situation.

I've setup my area with my controllers and I create the following area configuration:

Namespace Areas.Awesome

    Public Class AwesomeAreaRegistration
        Inherits AreaRegistration

        Public Overrides ReadOnly Property AreaName As String
            Get
                Return "Awesome"
            End Get
        End Property

        Public Overrides Sub RegisterArea(context As AreaRegistrationContext)

            context.MapRoute(
                "Awesome_default",
                "Awesome/{controller}/{action}/{id}",
                New With {.controller = "Sauce", .action = "Index", .id = UrlParameter.Optional},
                New String() {"Areas.Awesome"}
            )

        End Sub

    End Class

End Namespace

When I try to navigate to /Awesome/Sauce/ I get a 404 error and my site actually tries to route me to /Awesome/Sauce/Default.aspx.

HOWEVER, when I move the route to my RouteConfig:

Public Module RouteConfig

    Public Sub RegisterRoutes(ByVal routes As RouteCollection)
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
        routes.IgnoreRoute("{resource}.aspx/{*pathInfo}")

        routes.MapRoute(
            "Awesome_default",
            "Awesome/{controller}/{action}/{id}",
            New With {.controller = "Sauce", .action = "Index", .id = UrlParameter.Optional},
            New String() {"Areas.Awesome"}
        )
    End Sub

End Module

This serves up /Awesome/Sauce/ as expected.

I did some digging and created both routes at the same time, but with different URIs and I found they were both being defined in the same way, but one was working and one was not.

Is there something I'm missing with the area registration that would cause these routes to be ignored while the ones defined in RouteConfig are not?

afuzzyllama
  • 6,538
  • 5
  • 47
  • 64

1 Answers1

0

It may be with the way that the namespace is being applied with the area.

See this article

The namespace may just not be fully qualified for the area.

public class ContactsAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Contacts";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Contacts_default",
            "Contacts/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional },
            namespaces: new[] { "MvcApplication1.Areas.Contacts.Controllers" }
        );
    }
}
Community
  • 1
  • 1
Yo Adrian
  • 11
  • 2