【问题标题】:global axax overwriting current startup全局 axax 覆盖当前启动
【发布时间】:2018-04-20 14:23:28
【问题描述】:

我有一个现有项目,我想向其中添加 MVC。由于这个项目需要有一个API。我使用 .net 的 web api 框架

情况

我确实有一个文件在启动时运行,但 axax 正在覆盖它。

现在我想启动项目,但它不再执行我的旧文件,这导致它只启动 web api 需要的东西。

在web api初始化后,是否可以让启动项目的文件在应用程序中从全局axax开始?

全局.axax

protected void Application_Start(object sender, EventArgs e) 
{
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
}

【问题讨论】:

  • 有点晚了,但成功了,谢谢

标签: c# .net model-view-controller


【解决方案1】:

您实际上可以自己更新 Global.asax 并将您的代码包含在您调用 Application_Start 的块中。

https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/configuring-aspnet-web-api#webhost

在 ASP.NET 应用程序中,通过调用配置 Web API Application_Start 方法中的 GlobalConfiguration.Configure。这 配置方法接受一个具有单个参数类型的委托 Http配置。在 委托。

protected void Application_Start(object sender, EventArgs e) 
{
    AreaRegistration.RegisterAllAreas();
    GlobalConfiguration.Configure(WebApiConfig.Register);
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    // Your code here
}

【讨论】:

    猜你喜欢
    • 2014-09-27
    • 2013-05-27
    • 2019-07-14
    • 1970-01-01
    • 2020-07-28
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多