I ran this error attempting to handle multiple routes:
Server Error in '/' Application.
The layout page "Login" could not be found at the following path: "~/Views/Login/Login". Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The layout page "Login" could not be found at the following path: "~/Views/Login/Login".
Here is my route config code:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Login",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Dashboard",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
here is my _viewstart code
@{
string CurrentName = Convert.ToString(HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"]);
dynamic Layout;
switch (CurrentName)
{
case "Login":
Layout = "~/Views/Shared/_LoginPageLayout.cshtml";
break;
case "Dashboard":
Layout = "~/Views/Shared/_Layout.cshtml";
break;
default:
//Admin layout
Layout = "~/Views/Shared/_Layout.cshtml";
break;
}
}
Could I have some guidance as to where I might have taken a wrong turn?
in view start just use Layout = "~/Views/Shared/_Layout.cshtml";
remove this part => routes.MapRoute( name: "Login", url: "{controller}/{action}/{id}", defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional } );
just try to hit the index page of home (it's automatic with the route when your user try to reach your base site url )
and then filter the user with role on controller if not authentified redirect him to login.
dont try to break the framework in the early building of your site :)