我在ASP.NET MVC中使用CastleWindsor的依赖注入有一个WebApplication但是当我添加一个路由属性时,应用程序返回以下错误“找不到控制器”。
我的ControllerInstaller
public class ControllerInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Classes.FromThisAssembly()
.BasedOn<IController>()
.LifestyleTransient());
}
}
我有一个跟随控制器:
[Route("espetaculos")]
[FrontAuthorize]
public class EventController : Controller
{
#region DependencyInjection
private readonly IApplication applicationWeb;
private readonly IEventBusiness eventBusiness;
private readonly IShowBusiness showBusiness;
private readonly ISession sessionWeb;
private readonly ILog iLog;
public EventController(IEventBusiness eventBusiness, IShowBusiness showBusiness, IApplication applicationWeb, ISession sessionWeb, ILog iLog)
{
this.eventBusiness = eventBusiness;
this.showBusiness = showBusiness;
this.applicationWeb = applicationWeb;
this.sessionWeb = sessionWeb;
this.iLog = iLog;
}
当我访问路线“/ espetaculos”时,这里是错误
Castle希望只有控制器的完整路径?
修改 我的RouteConfig类
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
//routes.MapMvcAttributeRoutes();
//AreaRegistration.RegisterAllAreas();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Plateia.Controllers" }
);
}
}
答案 0 :(得分:0)
我怀疑,你显然没有在MVC中启用属性路由。如果不这样做,在控制器和操作上添加[Route]
属性将不起作用。
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
// This line is required in order to scan
// for [Route] attribute in your controllers
routes.MapMvcAttributeRoutes();
//AreaRegistration.RegisterAllAreas();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Plateia.Controllers" }
);
}
}