So I have a small snippet of code.
string requestedUrl = args.Context.Request.Url.AbsoluteUri;
Log.Warn($"Requested Url: '{requestedUrl}' being checked.", this);
var redirectTarget = _redirector.GetRedirectTarget(mapKey, requestedUrl.ToLowerInvariant());
if (!string.IsNullOrEmpty(redirectTarget))
{
Log.Warn($"Map 301 redirected '{args.Context.Request.Url.AbsoluteUri}' => {redirectTarget}", this);
args.AbortPipeline();
args.Context.Response.RedirectPermanent(redirectTarget);
}
And my problem is this; because the RedirectPermanent()
call essentially works by throwing an exception - nothing gets logged on those requests. Which is what surprises me. I would expect the Log.Warn($"Map 301...
log entry to always show up in my Sitecore log - but it doesn't.
The only log entries I get with this code, are like these:
31264 13:13:14 WARN Requested Url: 'http://myclient.dk/collections/myclientproduct' being checked.
Which is one of the target URLs in my code. The request that happened just prior, that was redirected to this page - is not shown in log.
What gives? And this must have been changed recently, no? I am almost certain, this behaviour wasn't always like this.
Edited to add
This code lives in a HttpRequestProcessor that is patched in right after the DatabaseResolver
in the <httpRequestBegin>
pipeline. While I don't know why, this seems to make a difference. Executing the above code in a normal page, works as expected.