CastleWindsor 无法在 asp.net mvc 中使用路由

CastleWindsor not working with route in asp.net mvc

我在 ASP.NET MVC 中有一个 WebApplication 使用 CastleWindsor 的依赖注入但是当我添加路由属性时,应用程序 returns 出现错误 "The controller no found".

我的控制器安装程序

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”时出现错误

城堡只需要控制器的完整路径?

编辑 我的路由配置 class

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" }
        );
    }
}

正如我所怀疑的,您显然没有在 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" }
        );
    }
}