lundi 16 mai 2016

WebActivatorEx.PostApplicationStartMethod() not called at startup

Trying to attach a WebActivatorEx.PostApplicationStartMethod() to an existing MVC 3 application, in particular RazorGenerator.

[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(TiPSViewWeb.RazorGeneratorMvcStart), "Start")]

namespace TiPSViewWeb {
    public static class RazorGeneratorMvcStart {
        public static void Start() {
            var engine = new PrecompiledMvcEngine(typeof(RazorGeneratorMvcStart).Assembly) {
                UsePhysicalViewsIfNewer = HttpContext.Current.Request.IsLocal
            };

            ViewEngines.Engines.Insert(0, engine);

            // StartPage lookups are done by WebPages. 
            VirtualPathFactoryManager.RegisterVirtualPathFactory(engine);
        }
    }
}

However this code is never executed during startup. I tried creating a new basic mvc application and installed Razor Generator into it, and the application is breaking nicely in the Start(). Am I missing a step here in order to make the app server call the right function? Is there anything that might be overshadowing that call?

I have this in Application_Start():

protected void Application_Start() { RouteTable.Routes.Ignore("{resource}.axd"); AreaRegistration.RegisterAllAreas();

RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);

InitSquishIt();

Application["ReportTasks"] = new Dictionary<long, Thread>();
Application["ReportTokens"] = new Dictionary<long, string>();

}

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{

}


//-----------------------------------------------------------------------------------
// Name:        RegisterRoutes
// Purpose:     Register the routes for the site.
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("admin/http://ift.tt/1rQjxp0}");
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
    routes.IgnoreRoute("Scripts/{folder}/{resource}.js.axd/{*pathInfo}");
    routes.IgnoreRoute("XML/{type}/{folder}/{resource}.xml.axd/{*pathInfo}");

    routes.MapRoute(
        "Report", // Route name
        "Report/{action}/{id}", // URL with parameters
        new
        {
            controller = "Report",
            action = "Main",
            id = ""
        }  // Parameter defaults
    );
    routes.MapRoute(
        "Base", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new
        {
            controller = "Base", action = "Main", id = UrlParameter.Optional
        }  // Parameter defaults
    );
}

Aucun commentaire:

Enregistrer un commentaire