asp.net – IControllerFactory’MyWebSite.WebUI.Infrastructure.
发布时间:2021-01-17 13:39:35 所属栏目:asp.Net 来源:互联网
导读:当我尝试在区域中的控制器中打开视图时,我得到了上述内容. Ninject设置如下: public class NinjectControllerFactory : DefaultControllerFactory{ private IKernel kernel = new StandardKernel(new RLSBCWebSiteServices()); protected
当我尝试在区域中的控制器中打开视图时,我得到了上述内容. Ninject设置如下: public class NinjectControllerFactory : DefaultControllerFactory { private IKernel kernel = new StandardKernel(new RLSBCWebSiteServices()); protected override IController GetControllerInstance(RequestContext context,Type controllerType) { if (controllerType == null) return null; return (IController)kernel.Get(controllerType); } private class MyWebSiteServices : NinjectModule { public override void Load() { Bind<IMatchesRepository>().To<SqlMatchesRepository>().WithConstructorArgument("connectionString",ConfigurationManager.ConnectionStrings["MyWebSiteDb"].ConnectionString); } } } 如果我在代码中放置断点,我看到RequestContext上下文包含以下值: context.RouteData.DataTokens.Values[0] = “MyWebSite.WebUI.Areas.Visitor” context.RouteData.DataTokens.Values[1] = “Visitor” which is the Area context.RouteData.Values.Values[0] = “admin” which is the Controller context.RouteData.Values.Values[1] = “register” which is the View 但是,controllerType == null,而不是控制器名称. 这个转移到新页面的过程是由 Html.ActionLink("here","Register","Admin",new { area = "Visitor" },null) 在登录页面上.但是如果我进入就会发生同样的事情 http://example.com/Visitor/admin/register 进入IE8 地区登记如下: public class VisitorAreaRegistration : AreaRegistration { public override string AreaName { get { return "Visitor"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Visitor_default","Visitor/{controller}/{action}/{id}",new { controller = "Admin",action = "Register",id = UrlParameter.Optional } ); } } 有没有人设法让区域使用NinjectControllerFactory,或者我的设置有问题? 解决方法而不是创建自己的NinjectControllerFactory使用最新版本的Ninject.Web.Mvc.它支持区域.见: https://github.com/ninject/ninject.web.mvc(编辑:哈尔滨站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET Web Api – 将对象发布到自定义动作
- 在ASP.NET MVC4中是否可以将C#或VB函数标记为Javascript?
- 将ASP.NET身份与核心域模型分离 – 洋葱架构
- 利用ASP.NET MVC和Bootstrap快速搭建个人博客之后台dataTab
- asp.net – “2015年4月20日Google帐户的OpenID2已经消失”
- asp.net-mvc-3 – 大量使用ViewBag
- asp.net – 如何序列化LINQ-to-SQL惰性列表
- asp.net-mvc – 如何在多个Asp.net MVC应用程序中使用通用布
- asp.net-mvc-3 – 如何从ASP.NET MVC#输出中删除空格?
- asp.net-mvc – MVC 5:Asp.net身份:如何建模UserRole