【发布时间】:2018-08-19 13:52:55
【问题描述】:
我用一些更相关的信息编辑了我的问题。
我有一个托管在IIS 上的Owin Web-Api 网站。
该应用程序有一个带有 2 个操作的控制器。
该应用程序运行良好。所有操作都返回有效结果。
当应用程序池被回收时,应用程序开始返回 404。 只有重建 bin 目录(我目前在本地工作)才能恢复应用程序(应用程序池上的 stop\start 不会做任何积极的事情)。
这就是我的 Startup.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.Register:
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
【问题讨论】:
-
请向我们显示工作和不工作请求的 URL。
-
@mjwills - 这是完全相同的请求(网址、标头、正文)。这就是为什么它让我发疯..
-
我猜,您在 IIS 中托管您的应用程序。应用程序被 IIS 回收后是否会出现这种情况(检查回收设置)?
-
你怎么知道应用程序没有突然关闭?可能存在空闲超时或应用程序崩溃。尝试在启动方法的开头添加显式日志并检查您是否只有一个启动事件。此外,请检查 Windows 事件日志以了解相关的错误事件。如果您一直调用您的应用程序,假设每 30 秒一次,您是否有相同的行为?
-
@SergeyL - 关于回收,我检查了事件日志。关于添加日志,这就是我现在正在做的在全局和中间件之间添加它们。当应用程序工作时,它可以流畅地服务请求。然后我停止向它发送请求几分钟,在接下来的请求中,我收到 404 响应,直到重建应用程序(我在本地工作)。
标签: c# iis asp.net-web-api owin