I have created a new ASP.NET MVC 5 project with Individual User Authentication in place. I have then gone ahead and installed Unity IoC as a package and configured that by doing the following inside UnityConfig.cs
:
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterTypes(AllClasses.FromLoadedAssemblies(), WithMappings.FromMatchingInterface, WithName.Default);
container.RegisterType<AccountController>(new InjectionConstructor());
}
From stuff I read through Google, this should take care of the fact that Unity would pick the constructor with most parameters. My AccountController.cs
has the following two constructors.
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
public AccountController()
{
}
public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager )
{
UserManager = userManager;
SignInManager = signInManager;
}
But still I am experiencing problems. When I navigate to http://localhost:xxxx/account/login
I get a 404 Error!
Here is my RouteConfig.cs
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Artist",
url: "{controller}/{urlfriendly}/{action}",
defaults: new { controller = "Artist", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
As I suspected, the problem is with your routes.
Think of routes like a switch case statement in c#. The issue you have is that whenever the first route encounters any 3 segment route, it will always match. Therefore, any normal /controller/action/id
will never hit your default route.
There needs to be either 1 or more constraints and/or 1 or more explicit segments in the route in order to ensure it doesn't match at some point, or you have basically made an unreachable execution path.
Here is an example with an explicit segment.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Artist",
url: "Artist/{urlfriendly}/{action}",
defaults: new { controller = "Artist", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);