代码之家  ›  专栏  ›  技术社区  ›  Amir Popovich

OWIN Web Api-对于最近返回200的请求,响应突然返回404

  •  1
  • Amir Popovich  · 技术社区  · 7 年前

    我用一些更相关的信息编辑了我的问题。

    我有一个 Owin Web-Api 托管在上的网站 IIS

    该应用程序有一个具有2个操作的单一控制器。
    该应用程序运行良好。所有操作都返回有效结果。

    当应用程序池被回收时,应用程序开始返回404。 只有重建bin目录(我目前正在本地工作)才能恢复应用程序(在应用程序池上停止\启动不会起任何积极作用)。

    这就是我 启动。cs公司 看起来像:

    var httpConfiguration = new HttpConfiguration();
    WebApiConfiguration.Register(httpConfiguration); // will show it's content later
    
    appBuilder.UseRequestScopeContext(); // Third party OwinRequestScopeContext
    appBuilder.Use<IOCContainerMiddleware>(); // Custom middleware that creates an IOC container per request and disposes it at the end of the request
    
    appBuilder.UseWebApi(httpConfiguration);
    

    WebApiConfiguration。登记 :

    config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "{controller}/{action}",
    constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) },
    defaults: null);
    
    ConfigureDependencyResolver(config); // Custom dependency resolver that uses the IOC container from above
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Amir Popovich    7 年前

    我发现了问题。

    我的启动类位于外部dll上,该dll引用到我的应用程序(并存在于我的bin文件夹中)。

    我添加 "owin:appStartup" my中的密钥 appSettings 我的网站内的部分。配置:

    <appSettings>
        <add key="owin:appStartup" value="WebApiServicePrototype.Startup.ServiceStartup, WebApiServicePrototype" />
    </appSettings>
    

    owin:appStartup 键指向它工作的外部dll,直到应用程序的应用程序池被回收(我在IIS上托管),然后开始抛出404个结果。

    owin:应用程序启动 指向当前应用程序dll中存在的启动类,一切正常。

    现在,我在应用程序的dll上创建了一个虚拟适配器,并将 owin:应用程序启动 指向它。

    我不确定这是不是有意的。