2

I seem to be having an issue with either namespacing or Registration. At this point, I am leaning more towards area and registration issues with MVC 3.0, but I am open to any ideas here.

My CAPAreaRegistration.cs file looks ike this:

  namespace CISE.CINet.UserInterface.Areas.CAP
{
    public class CAPAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "CAP";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "CAP_default",
                "CAP/{controller}/{action}/{id}",
                new { action = "NewNomination", id = UrlParameter.Optional }
            );
        }
    }
}

I have also tried adding the namespace i changed everything to:

  public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "CAP_default",
                "CAP/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }, new string[] { "CISE.CINet.UserInterface.Areas.CAP.Controllers" }  // specify the new namespace 
            );
        }

The Global.asax looks like this:

    namespace CISE.CINet.UserInterface
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        #region PUBLIC FIELDS TO ALL APPLICATIONS

        //public static string SERVER_NAME = "ri-cinet-prd";
        public static string SERVER_NAME = "se-cinet-dev";
        public static string SHAREPOINT_PATH = "http://se-spoint-dev/";

        #endregion

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


            routes.MapRoute(
                "CAPLogin",
                "CAP/WelcomePartial",
                new { controller = "Home", action = "WelcomePartial", id = UrlParameter.Optional }
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }

The Home Controller works, but trying to go to CAP/NewNomination or CAP/Index does not work? I am getting a 404 error:

It directs to NewNomination, but i try index as well to no avail

Any ideas? Is my URL path incorrect?

Wiebe Tijsma
  • 10,173
  • 5
  • 52
  • 68
gcoleman0828
  • 1,541
  • 3
  • 30
  • 49

3 Answers3

14

Try change the namespace for your area registration class to be the same as in your Global.asax.cs file.

I had the same problem, and this fixed it for me at least.

Anttu
  • 1,076
  • 1
  • 10
  • 21
0

I'm using autofac as DI container, and ran into the same problem. Instead of changing/registering the namespaces, it's possible to just register the area's hard coded (least delay anyway in startup):

var area = new MyAreaRegistration();
var rc = new AreaRegistrationContext(area.AreaName, RouteTable.Routes);
area.RegisterArea(rc);

Or resolve them from your container like this:

foreach (var area in container.Resolve<IEnumerable<AreaRegistration>>())
{
  var rc = new AreaRegistrationContext(area.AreaName, RouteTable.Routes);
   area.RegisterArea(rc);
}
Wiebe Tijsma
  • 10,173
  • 5
  • 52
  • 68
-9

That and adding the namespace in the registration fixed it:

new[]{ "CISE.CINet.UserInterface.Areas.CAP.Controllers" }
gcoleman0828
  • 1,541
  • 3
  • 30
  • 49