我正在构建我的第一个Asp.Net MVC2网站,现在我正在尝试向该网站添加一个/ Admin区域。使用管理子网站进行路由的正确流程
我不希望这个地区是分享范围主要组用户,所以当你进入http://Intranet/Admin
我已经是一个NewsController我的普通用户,但我也想要一个管理员NewsController将只能访问我不知道如何设置类层次结构和文件夹,以便在添加视图时它们位于正确的位置。
我在我的Global.Asax.cs里面添加了并且正确解析了路由。
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "Intranet.Controllers" }
);
routes.MapRoute(
"Admin", // Route name
"Admin/{controller}/{action}/{id}", // URL with parameters
new { controller = "Admin", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "Intranet.Controllers.Admin" }
);
而在文件夹层次我设置
Views/
Admin/
News/
...I want the new view to go here...
在控制器
Controllers/
Admin/
AdminController.cs
NewsController.cs (this is the one i want for administration)
NewsController.cs (this is the regular one for viewing the list, specific item etc)
我所面临的问题是,当我进入对指数的管理员/ NewsController.cs并添加查看它尝试在/News/Index.aspx而不是/Admin/News/Index.aspx创建它。
这是我的C114讯控制器控制器/管理 - >添加 - >控制器
namespace Intranet.Controllers.Admin
{
public class NewsController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
的代码是不是有什么我做不正确,或者我应该怎么改变,这样,当我添加的意见它们正在/ Admin/{area}目录中创建。
谢谢。花了一点时间,我的脑袋围绕着额外的控制器步骤来分离两个区域,但现在都很好 – 2010-10-07 03:15:49