2010-07-22 80 views
0

我需要帮助。我无法从我的主项目访问我的便携式区域。我构建了一切,当试图访问这个便携式区域(localhost:123/IW/Home)时出现404错误,但我所有常规区域都正常工作(例如:localhost:123/Portal/Home)无法访问MVCContrib中的我的便携式区域MVC2

Here's我为了做安装我的便携式区域 -I下载MVCContrib -I添加参考MVCContrib.dll在我的主要项目(称为WAB)

-I创建在同一个解决方案WAB一个新的类Librairy项目。 - 此新类Librairy称为IWPortableArea和我添加了必要的程序集的引用(MVCContrib,System.mvc,...)

-I创建IWRegistration:

namespace IWPortableArea 
{ 
    public class IWRegistration : PortableAreaRegistration 
    { 
     public override void RegisterArea(System.Web.Mvc.AreaRegistrationContext context, IApplicationBus bus) 
     { 
      context.MapRoute(
       "iw", 
       "iw/{controller}.aspx/{action}", 
       new { controller = "login", action = "index" }); 

      RegisterAllAreas(GetType()); 
     } 

     public override string AreaName 
     { 
      get { return "iw"; } 
     } 


    } 
} 

-I创建了一个简单的控制器这不是利用任何视图文件:

namespace IWPortableArea.Controllers 
{ 
    public class HomeController : Controller 
    { 
     public ActionResult Index() 
     { 
      return Content("yo you are in IW Portable Area, congrats"); 
     } 
    } 
} 

-I加入我的主要项目,便携式区域的引用:IWPortableArea.dll

- 最后我修改我的主要应用程序的Global.asax.cs中来:

public class MvcApplication : System.Web.HttpApplication 
    { 
     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 


      routes.MapRoute(
       "Default", // Route name 
       "{controller}.aspx/{action}/{id}", // URL with parameters 
       new { controller = "Portal", action = "Index", id = UrlParameter.Optional } // Parameter defaults 
      ); 
     } 

     protected void Application_Start() 
     { 
      AreaRegistration.RegisterAllAreas(); 

      RegisterRoutes(RouteTable.Routes); 
     } 
    } 
+0

什么是“iw/{controller} .aspx/{action}”中的aspx? – jfar 2010-07-22 18:04:05

+0

我们的网络服务器上的IIS不支持“.aspx”而不支持.aspx没有.aspx我得到一个404错误。所以在我的文章中,当我说http:// localhost:123/IW/Home时,它应该是http:// localhost:123/IW/Home.aspx – 2010-07-22 18:13:15

+0

您是否已将区域视图的编译操作更改为Embedded Resource? – 2010-09-10 06:10:39

回答

2

记住创建与托管应用程序的名称“区域”的文件夹。这解决了我的问题。