【问题标题】:Can't acces my Portable Area in MVCContrib MVC2无法在 MVC Contrib MVC2 中访问我的便携式区域
【发布时间】:2010-07-22 16:05:54
【问题描述】:

我需要帮助。我无法从我的主项目访问我的便携式区域。我构建了所有内容,但在尝试访问此便携式区域(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);
        }
    }

【问题讨论】:

  • “iw/{controller}.aspx/{action}”中的aspx是干什么用的?
  • 我们网络服务器上的 IIS 确实支持没有“.aspx”的 url 如果没有 .aspx,我会收到 404 错误。所以在我的帖子中,当我说localhost:123/IW/Home 时,它应该是localhost:123/IW/Home.aspx
  • 你把区域视图的编译动作改成嵌入式资源了吗?

标签: asp.net-mvc asp.net-mvc-2 mvccontrib portable-areas


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多