Handle a few other potentially null properties (#10053)

This commit is contained in:
Justin Kotalik 2019-05-14 18:08:05 -07:00 committed by GitHub
parent 93af64823e
commit 47575a08a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 5 deletions

View File

@ -81,15 +81,21 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
private void InitializeLocalEndpoint() private void InitializeLocalEndpoint()
{ {
var localEndPoint = GetLocalEndPoint(); var localEndPoint = GetLocalEndPoint();
LocalIpAddress = localEndPoint.GetIPAddress(); if (localEndPoint != null)
LocalPort = localEndPoint.GetPort(); {
LocalIpAddress = localEndPoint.GetIPAddress();
LocalPort = localEndPoint.GetPort();
}
} }
private void InitializeRemoteEndpoint() private void InitializeRemoteEndpoint()
{ {
var remoteEndPoint = GetRemoteEndPoint(); var remoteEndPoint = GetRemoteEndPoint();
RemoteIpAddress = remoteEndPoint.GetIPAddress(); if (remoteEndPoint != null)
RemotePort = remoteEndPoint.GetPort(); {
RemoteIpAddress = remoteEndPoint.GetIPAddress();
RemotePort = remoteEndPoint.GetPort();
}
} }
private void InitializeConnectionId() private void InitializeConnectionId()

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -14,6 +15,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace TestSite namespace TestSite
@ -103,6 +105,12 @@ namespace TestSite
public Task CreateFile(HttpContext context) public Task CreateFile(HttpContext context)
{ {
var hostingEnv = context.RequestServices.GetService<IWebHostEnvironment>(); var hostingEnv = context.RequestServices.GetService<IWebHostEnvironment>();
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"), ""); File.WriteAllText(System.IO.Path.Combine(hostingEnv.ContentRootPath, "Started.txt"), "");
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -43,7 +43,6 @@ namespace Microsoft.AspNetCore.HttpSys.Internal
_permanentlyPinned = true; _permanentlyPinned = true;
} }
internal SafeNativeOverlapped NativeOverlapped => _nativeOverlapped; internal SafeNativeOverlapped NativeOverlapped => _nativeOverlapped;
internal HttpApiTypes.HTTP_REQUEST* NativeRequest internal HttpApiTypes.HTTP_REQUEST* NativeRequest