Discusses some issues related to mvc2.0
Posted
by
hao123
on Stack Overflow
See other posts from Stack Overflow
or by hao123
Published on 2010-12-29T05:50:20Z
Indexed on
2010/12/29
5:53 UTC
Read the original article
Hit count: 219
???????????????,????????
??:
???????:1????????2????????3????
??????????????
??????:1???????:http://demo.com/admin/News/index
2???????:http://demo.com/s7mmer/News/index
3?????:http://demo.com/News/index
??asp.net mvc1.0???????????,?????,??asp.net mvc2.0???Areas??
??:
???????,?????????????Admin?areas,??VS?????????????areas????,?????????????????
??????????:
1?????????Areas????
2??Areas ????????
3?????,?Areas?????????MyAreaRegistration.cs
????:
?? using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace S7mmer.Web { public class AdminAreaRegistration : AreaRegistration { public override string AreaName { get { return "Admin"; } } public override void RegisterArea(AreaRegistrationContext context) { //?????????? context.MapRoute( "AdminController_default", "Admin/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" }, // Parameter defaults new string[] { "S7mmer.Web.Areas.Admin.Controllers" }//controllers????? ); } } public class S7mmerAreaRegistration : AreaRegistration { public override string AreaName { get { return "S7mmer"; } } public override void RegisterArea(AreaRegistrationContext context) { //?????????? context.MapRoute( "S7mmerController_default", "S7mmer/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" }, // Parameter defaults new string[] { "S7mmer.Web.Areas.S7mmer.Controllers" }//controllers????? ); } }
public class WebSiteAreaRegistration : AreaRegistration
{
public override string AreaName
{
get { return "WebSite"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
//??????????
context.MapRoute(
"WebSiteController_default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }, // Parameter defaults
new string[] { "S7mmer.Web.Areas.WebSite.Controllers" }//controllers?????
);
}
}
}
4??Areas?????Admin????????NewsController.cs
5??NewsController.cs??public ActionResult Index()?????view,???
???news????index.aspx
6????????Global.asax??,?Application_Start()????AreaRegistration.RegisterAllAreas();
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// RegisterRoutes(RouteTable.Routes);
}
????? http://localhost:1108/admin/News/index,??????????!
??????????????????,???????????????,????
© Stack Overflow or respective owner