无法访问 MVCContrib MVC2 中的我的可移植区域

发布于 2024-09-11 03:57:26 字数 1968 浏览 8 评论 0原文

我需要帮助。我无法从我的主项目访问我的便携式区域。我构建了所有内容,并在尝试访问此可移植区域(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪落纷纷 2024-09-18 03:57:26

请记住在托管应用程序中创建一个名为“Areas”的文件夹。这解决了我的问题。

Remember to create a folder with the name "Areas" in the hosting application. This solved my problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文