Reputation: 731
I have created an "admin" area within my asp.net mvc 4 project. For now this area has just the basic's. Ideally, once the application runs, I want to the user to type /Admin in the URL and be re-directed to the Admin Index view. However when I run the program I get an error stating that "Admin cannot be found" ?? Am I missing a reference somewhere ??
Also, a regular user login page is the first view rendered, I need to bypass that login page to get to the Admin section. However I believe the following line is preventing a second log in option.
WebSecurity.InitializeDatabaseConnection("Portal.Model.PortalDBContext","PatientPortalAccount", "PatientID", "Username", autoCreateTables: true);
Please keep in mind I cannot alter the regular user tables to include roles. If you haven't noticed already I'm still learning, so apologies for the long winded question...
admincontoller,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Portal.Web.Areas.Admin.Controllers
{
public class AdminController : Controller
{
//
// GET: /Admin/Admin/
public ActionResult Index()
{
return View();
}
with an index actionResult, which has a view.
@model Portal.Model.AdminDetails
@{
ViewBag.Title = "Admin";
Layout = "~/Views/Shared/Login.cshtml";
}
This area also has the generated .cs file AdminAreaRegistration
using System.Web.Mvc;
namespace Portal.Web.Areas.Admin
{
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Admin", action = "Index", id = UrlParameter.Optional },
new [] { "Admin.Controllers" }
);
}
}
}
And within the Global.asax file....
using System;
using System.Linq;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using WebMatrix.WebData;
namespace Portal.Web
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
WebSecurity.InitializeDatabaseConnection("Portal.Model.PortalDBContext", "PatientPortalAccount", "PatientID", "Username", autoCreateTables: true);
//BOC - Remove Web Forms View Engine
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
}
}
Upvotes: 0
Views: 329
Reputation: 24832
You have a namespace constraint in your route: "Admin.Controllers
" but your controller is in namespace "Portal.Web.Areas.Admin.Controllers
"
Upvotes: 1