I have created a catch-all rule to abort any/all requests not matched by earlier rewrite rules:
/// <summary>
/// <rule name="AbortAllRequestsRule" patternSyntax="ECMAScript" stopProcessing="true">
/// <match url=".*" />
/// <action type="AbortRequest" />
/// </rule>
/// </summary>
public class AbortAllRequestsRule : IRule
{
private readonly IISUrlRewriteRule _rule;
public AbortAllRequestsRule()
{
// create rule builder
var ruleBuilder = new UrlRewriteRuleBuilder
{
Name = nameof(AbortAllRequestsRule),
Enabled = true
};
// add url match
ruleBuilder.AddUrlMatch(
".*",
ignoreCase: true,
negate: false,
patternSyntax: PatternSyntax.ECMAScript);
// add action
var action = new AbortAction();
ruleBuilder.AddUrlAction(action);
// create rule
_rule = ruleBuilder.Build(true);
}
public void ApplyRule(RewriteContext context)
{
_rule.ApplyRule(context);
}
}
In Kestrel, this properly aborts the request. However, IIS sees an aborted request, and without additional configuration, throws a very detailed 502 response (HTML page).
Pares the verbose 502 response down to a more reasonable one:
HTTP/1.1 502 Bad Gateway
Content-Type: text/html
Server: Microsoft-IIS/8.5
Date: Fri, 03 Feb 2017 19:53:07 GMT
Content-Length: 89
The specified CGI application encountered an error and the server terminated the process.
But, is it possible to have IIS properly proxy the lack of a response from Kestrel and, itself, abort the response rather than returning a 502?
I have created a catch-all rule to abort any/all requests not matched by earlier rewrite rules:
In Kestrel, this properly aborts the request. However, IIS sees an aborted request, and without additional configuration, throws a very detailed 502 response (HTML page).
Adding the following snippet to
web.config
:Pares the verbose 502 response down to a more reasonable one:
But, is it possible to have IIS properly proxy the lack of a response from Kestrel and, itself, abort the response rather than returning a 502?