diff --git a/src/Servers/IIS/IIS/src/Core/IISHttpContext.IHttpConnectionFeature.cs b/src/Servers/IIS/IIS/src/Core/IISHttpContext.IHttpConnectionFeature.cs index 40b70a2b90..59b5d487f3 100644 --- a/src/Servers/IIS/IIS/src/Core/IISHttpContext.IHttpConnectionFeature.cs +++ b/src/Servers/IIS/IIS/src/Core/IISHttpContext.IHttpConnectionFeature.cs @@ -81,15 +81,21 @@ namespace Microsoft.AspNetCore.Server.IIS.Core private void InitializeLocalEndpoint() { var localEndPoint = GetLocalEndPoint(); - LocalIpAddress = localEndPoint.GetIPAddress(); - LocalPort = localEndPoint.GetPort(); + if (localEndPoint != null) + { + LocalIpAddress = localEndPoint.GetIPAddress(); + LocalPort = localEndPoint.GetPort(); + } } private void InitializeRemoteEndpoint() { var remoteEndPoint = GetRemoteEndPoint(); - RemoteIpAddress = remoteEndPoint.GetIPAddress(); - RemotePort = remoteEndPoint.GetPort(); + if (remoteEndPoint != null) + { + RemoteIpAddress = remoteEndPoint.GetIPAddress(); + RemotePort = remoteEndPoint.GetPort(); + } } private void InitializeConnectionId() diff --git a/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ServicesTests.cs b/src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ApplicationInitializationTests.cs similarity index 100% rename from src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ServicesTests.cs rename to src/Servers/IIS/IIS/test/IIS.Shared.FunctionalTests/ApplicationInitializationTests.cs diff --git a/src/Servers/IIS/IIS/test/testassets/shared/SharedStartup/Startup.shared.cs b/src/Servers/IIS/IIS/test/testassets/shared/SharedStartup/Startup.shared.cs index ba16ed976a..63afe25ac9 100644 --- a/src/Servers/IIS/IIS/test/testassets/shared/SharedStartup/Startup.shared.cs +++ b/src/Servers/IIS/IIS/test/testassets/shared/SharedStartup/Startup.shared.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -14,6 +15,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.DependencyInjection; namespace TestSite @@ -103,6 +105,12 @@ namespace TestSite public Task CreateFile(HttpContext context) { var hostingEnv = context.RequestServices.GetService(); + + if (context.Connection.LocalIpAddress == null || context.Connection.RemoteIpAddress == null) + { + throw new Exception("Failed to set local and remote ip addresses"); + } + File.WriteAllText(System.IO.Path.Combine(hostingEnv.ContentRootPath, "Started.txt"), ""); return Task.CompletedTask; } diff --git a/src/Shared/HttpSys/RequestProcessing/NativeRequestContext.cs b/src/Shared/HttpSys/RequestProcessing/NativeRequestContext.cs index 26c01e4868..c55364f561 100644 --- a/src/Shared/HttpSys/RequestProcessing/NativeRequestContext.cs +++ b/src/Shared/HttpSys/RequestProcessing/NativeRequestContext.cs @@ -43,7 +43,6 @@ namespace Microsoft.AspNetCore.HttpSys.Internal _permanentlyPinned = true; } - internal SafeNativeOverlapped NativeOverlapped => _nativeOverlapped; internal HttpApiTypes.HTTP_REQUEST* NativeRequest