Logging#543 Reorder request disposal due to logging.
This commit is contained in:
parent
9c78b5a8be
commit
e3c7e23cc4
|
|
@ -204,17 +204,18 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
{
|
{
|
||||||
await _application.ProcessRequestAsync(context).SupressContext();
|
await _application.ProcessRequestAsync(context).SupressContext();
|
||||||
await featureContext.OnResponseStart();
|
await featureContext.OnResponseStart();
|
||||||
requestContext.Dispose();
|
|
||||||
_application.DisposeContext(context, null);
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
await featureContext.OnCompleted();
|
await featureContext.OnCompleted();
|
||||||
}
|
}
|
||||||
|
_application.DisposeContext(context, null);
|
||||||
|
requestContext.Dispose();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogHelper.LogException(_logger, "ProcessRequestAsync", ex);
|
LogHelper.LogException(_logger, "ProcessRequestAsync", ex);
|
||||||
|
_application.DisposeContext(context, ex);
|
||||||
if (requestContext.Response.HasStarted)
|
if (requestContext.Response.HasStarted)
|
||||||
{
|
{
|
||||||
requestContext.Abort();
|
requestContext.Abort();
|
||||||
|
|
@ -225,7 +226,6 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
requestContext.Response.Headers.Clear();
|
requestContext.Response.Headers.Clear();
|
||||||
SetFatalResponse(requestContext, 500);
|
SetFatalResponse(requestContext, 500);
|
||||||
}
|
}
|
||||||
_application.DisposeContext(context, ex);
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Testing.xunit;
|
using Microsoft.AspNetCore.Testing.xunit;
|
||||||
|
|
@ -165,6 +166,34 @@ namespace Microsoft.AspNetCore.Server.HttpSys
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/aspnet/Logging/issues/543#issuecomment-321907828
|
||||||
|
[ConditionalFact]
|
||||||
|
public async Task AuthTypes_AccessUserInOnCompleted_Success()
|
||||||
|
{
|
||||||
|
var completed = new ManualResetEvent(false);
|
||||||
|
string userName = null;
|
||||||
|
var authTypes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;
|
||||||
|
using (var server = Utilities.CreateDynamicHost(authTypes, DenyAnoymous, out var address, httpContext =>
|
||||||
|
{
|
||||||
|
Assert.NotNull(httpContext.User);
|
||||||
|
Assert.NotNull(httpContext.User.Identity);
|
||||||
|
Assert.True(httpContext.User.Identity.IsAuthenticated);
|
||||||
|
httpContext.Response.OnCompleted(() =>
|
||||||
|
{
|
||||||
|
userName = httpContext.User.Identity.Name;
|
||||||
|
completed.Set();
|
||||||
|
return Task.FromResult(0);
|
||||||
|
});
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
var response = await SendRequestAsync(address, useDefaultCredentials: true);
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
|
Assert.True(completed.WaitOne(TimeSpan.FromSeconds(5)));
|
||||||
|
Assert.False(string.IsNullOrEmpty(userName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[InlineData(AuthenticationSchemes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationSchemes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue