加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-2 – 从.NET MVC 1迁移到MVC 2 RC

发布时间:2020-12-16 06:52:44 所属栏目:asp.Net 来源:网络整理
导读:我已将MVC1项目迁移到MVC2 RC,现在该站点根本不起作用.我收到错误“找不到入口点”. 我在this link之后迁移了这个项目 我正在使用Castle Windsor作为DI. 这是global.asax.cs的一部分 public static void RegisterRoutes(RouteCollection routes) { routes.Ig
我已将MVC1项目迁移到MVC2 RC,现在该站点根本不起作用.我收到错误“找不到入口点”.

我在this link之后迁移了这个项目

我正在使用Castle Windsor作为DI.

这是global.asax.cs的一部分

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default","{controller}/{action}/{id}",new { controller = "Main",action = "Index",id = "" });
    }

    protected void Application_Start()
    {
        log4net.Config.XmlConfigurator.Configure();
        InitializeServiceLocator();
        //RouteConfigurator.RegisterRoutesTo(RouteTable.Routes);
        AreaRegistration.RegisterAllAreas();
        RegisterRoutes(RouteTable.Routes);

        Bootstrapper.BootStrap();
    }

    /// <summary>
    /// If you need to communicate to multiple databases,you'd add a line to this method to
    /// initialize the other database as well.
    /// </summary>
    private void InitializeNHibernateSession()
    {
        var cfg =
            NHibernateSession.Init(
                webSessionStorage,new string[] { Server.MapPath("~/bin/Edi.Advance.EPortfolio.Data.dll") },new AutoPersistenceModelGenerator().Generate(),Server.MapPath("~/hibernate.cfg.xml")).AddAssembly(typeof(ISoftDeletable).Assembly).AddAssembly(
                typeof(Action).Assembly);

        //cfg.SetListener(ListenerType.Delete,new AdvanceDeleteEventListener(IoC.Resolve<ISecurityContextService>()));
        //cfg.SetListener(ListenerType.SaveUpdate,new AdvanceSaveUpdateEventListener(IoC.Resolve<ISecurityContextService>()));
    }

    /// <summary>
    /// Instantiate the container and add all Controllers that derive from 
    /// WindsorController to the container.  Also associate the Controller 
    /// with the WindsorContainer ControllerFactory.
    /// </summary>
    protected virtual void InitializeServiceLocator()
    {
       // AddComponentsToIoC();
        var container = new WindsorContainer();

        ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
        container.RegisterControllers(typeof(MainController));

        ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));

    }

MainController非常简单,Index动作只返回“Hello World from MVC2”字符串. (没有观点这个动作).

有趣的是,如果我注释掉这一行:

ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

MainController工作正常,但是由于其他更复杂的控制器不起作用,说没有无参数构造函数.

所以它接缝是WindsorControllerFactory的错误.

有任何想法吗?
谢谢

解决方法

使用:
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext,Type controllerType)

Insted:protected override IController GetControllerInstance(Type controllerType)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读