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()
{
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()

View File

@ -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<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"), "");
return Task.CompletedTask;
}

View File

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