无法访问 MVCContrib MVC2 中的我的可移植区域
我需要帮助。我无法从我的主项目访问我的便携式区域。我构建了所有内容,并在尝试访问此可移植区域(localhost:123 / IW / Home)时收到404错误,但我所有的常规区域都工作正常(例如:localhost:123 / Portal / Home)
这是我所做的为了安装我的便携式区域 -我下载了 MVCContrib -我在主项目(称为 WAB)中添加了对 MVCContrib.dll 的引用
-我在与 WAB 相同的解决方案中创建了一个新的类库项目。 -这个新的类库称为 IWPortableArea,我添加了必要的程序集引用(MVCContrib、System.mvc 等)
-我创建了一个 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"; }
}
}
}
-我创建了一个不使用任何视图文件的简单控制器:
namespace IWPortableArea.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return Content("yo you are in IW Portable Area, congrats");
}
}
}
-我添加了我的主项目中对可移植区域的引用: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);
}
}
I need help. I can't access my portable area from my main project. I build everything and I get a 404 error when trying to access this portable area (localhost:123/IW/Home), but all my regular areas are working fine (ex: localhost:123/Portal/Home)
Here's what I did in order to install my portable area
-I downloaded MVCContrib
-I added reference to MVCContrib.dll in my main project (called WAB)
-I created a new Class Librairy project in the same solution as WAB.
-This new Class Librairy is called IWPortableArea and I added the necessary assemblies references (MVCContrib, System.mvc, ...)
-I created a 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 created a simple controller that's not making use of any view file:
namespace IWPortableArea.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return Content("yo you are in IW Portable Area, congrats");
}
}
}
-I added a reference in my main project to the portable area: IWPortableArea.dll
-Finally I modified the Global.asax.cs of my main application to:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住在托管应用程序中创建一个名为“Areas”的文件夹。这解决了我的问题。
Remember to create a folder with the name "Areas" in the hosting application. This solved my problem.