几小时后,网络API路由停止运行

时间:2017-02-11 13:11:24

标签: asp.net asp.net-mvc routing asp.net-web-api2 asp.net-web-api-routing

我在visual studio中使用web api处理asp.net mvc项目。

我的网络API路由工作做得很好,但经过几个小时的停止并在消息下显示(但mvc项目正常工作):

  

服务器错误
  404 - 找不到文件或目录   你是资源   寻找可能已被删除,更改名称,或者是   暂时不可用。

如何解决这个问题?

更新(更多详情):

的global.asax

        //register AppBase
        AppBase.Intro.Register();

        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

        //register modules
        //this method trigger a event and run all of modules that hook to event
        ModuleActivator.AutoRegiterModules();

        //event
        var argsStarting = new Global.ApplicationStartingEventArgs();
        Global.OnApplicationStarting(argsStarting);

        //event
        var argsRouting = new Global.ApplicationRouteEventArgs();
        argsRouting.Routes = RouteTable.Routes;
        Global.OnApplicationBeforeRouting(argsRouting);

        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);

我的模块之一是在其他项目中创建的“内容管理器api”。

这是web api路由代码:

    public const string RoutePerfix = "api/ContentManager/";
    public static void Register(HttpConfiguration config)
    {
        // Web API routes
        try
        {
            config.MapHttpAttributeRoutes();
        }
        catch (Exception)
        {
            // ignored
        }

        config.Routes.MapHttpRoute(
            name: Intro.ModuleName,
            routeTemplate: RoutePerfix + "{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }

解决:

我使用AppDomain.CurrentDomain.GetAssemblies()来获取我的模块类来运行它们。但是当IIS上的应用程序在下次重新启动AppDomain.CurrentDomain.GetAssemblies()方法时被杀死时,不会返回所有程序集。所以将AppDomain.CurrentDomain.GetAssemblies()更改为BuildManager.GetReferencedAssemblies()方法,问题就解决了。

0 个答案:

没有答案