【发布时间】:2016-03-23 19:18:21
【问题描述】:
我在调试 ASP.NET Web 应用程序 (.NET 4.6.1) 时注意到一个奇怪的行为。每当发生 HTTP 错误(例如 404 或 403)时,请求都会重复最多 3 次。
我使用 fiddler 测试了这个单一问题,Intellitrace 有效地向我显示了三个相同的请求(即使我只发送一个请求)。
我可以看到这个问题的影响,因为管道中的任何 Owin 中间件都被调用了 3 次。像这样一个简单的中间件:
app.Use(async (c, n) =>
{
Debug.WriteLine("HIT!");
await n.Invoke();
});
将打印三个连续的“HIT!”进入控制台。
只有在请求产生错误时才会发生这种情况,而不是在请求由中间件处理时才会发生(例如,如果中间件以 2XX 状态码响应时不会发生这种情况)。
发生了什么事?
我在 Win10 上运行 VS2015 和 IIS Express 10。
[编辑] 可能与我的 Web.config 配置有关?我正在添加一段摘录。
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" enableVersionHeader="false" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
</customHeaders>
<redirectHeaders>
<clear />
</redirectHeaders>
</httpProtocol>
<security>
<requestFiltering removeServerHeader="true" />
</security>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
【问题讨论】:
-
向我们展示产生错误的代码。它不一定是你的代码;它只需要重现问题。
-
没有代码产生错误。在示例中我向
https://localhost:44300发出请求,IIS 直接返回 403 状态码。如果我向不存在的端点(例如localhost:44300/somethingnonexisting)发出请求,并且 IIS 返回 404,也是一样的。 -
另请注意,目前 Owin 管道中没有其他内容,只有示例中显示的中间件。
标签: c# asp.net iis owin iis-express