diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs index 942e1d3bfb..2827d397a5 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHostingEnvironment.cs @@ -26,10 +26,15 @@ namespace Umbraco.Web.BackOffice.AspNetCore // IISVersion = HttpRuntime.IISVersion; IsDebugMode = _hostingSettings.DebugMode; } - + public bool IsHosted { get; } = true; public string SiteName { get; } public string ApplicationId { get; } public string ApplicationPhysicalPath { get; } + + public string ApplicationVirtualPath { get; } + public bool IsDebugMode { get; } + + public string LocalTempPath { get @@ -67,9 +72,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore } } } - public string ApplicationVirtualPath { get; } - public bool IsDebugMode { get; } - public bool IsHosted { get; } = true; + public Version IISVersion { get; } public string MapPath(string path) => Path.Combine(_webHostEnvironment.WebRootPath, path); diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs index 31aefdee89..696005f2fb 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreHttpContextAccessor.cs @@ -1,6 +1,4 @@ -using System; -using System.Web; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; namespace Umbraco.Web.BackOffice.AspNetCore { diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs index e6be7449e1..8f231191f2 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreIpResolver.cs @@ -1,4 +1,3 @@ -using System; using Microsoft.AspNetCore.Http; using Umbraco.Net; @@ -13,6 +12,6 @@ namespace Umbraco.Web.BackOffice.AspNetCore _httpContextAccessor = httpContextAccessor; } - public string GetCurrentRequestIpAddress() => _httpContextAccessor?.HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? String.Empty; + public string GetCurrentRequestIpAddress() => _httpContextAccessor?.HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? string.Empty; } } diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreUmbracoApplicationLifetime.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreUmbracoApplicationLifetime.cs new file mode 100644 index 0000000000..1d713794cc --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreUmbracoApplicationLifetime.cs @@ -0,0 +1,36 @@ +using System.Threading; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Umbraco.Net; + +namespace Umbraco.Web.AspNet +{ + public class AspNetCoreUmbracoApplicationLifetime : IUmbracoApplicationLifetime + { + private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IApplicationLifetime _applicationLifetime; + + public AspNetCoreUmbracoApplicationLifetime(IHttpContextAccessor httpContextAccessor, IApplicationLifetime applicationLifetime) + { + _httpContextAccessor = httpContextAccessor; + _applicationLifetime = applicationLifetime; + } + + public bool IsRestarting { get; set; } + public void Restart() + { + IsRestarting = true; + + var httpContext = _httpContextAccessor.HttpContext; + if (httpContext != null) + { + // unload app domain - we must null out all identities otherwise we get serialization errors + // http://www.zpqrtbnk.net/posts/custom-iidentity-serialization-issue + httpContext.User = null; + } + + Thread.CurrentPrincipal = null; + _applicationLifetime.StopApplication(); + } + } +} diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreUserAgentProvider.cs b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreUserAgentProvider.cs new file mode 100644 index 0000000000..f9c9884704 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/AspNetCore/AspNetCoreUserAgentProvider.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Http; +using Umbraco.Net; + +namespace Umbraco.Web.BackOffice.AspNetCore +{ + public class AspNetCoreUserAgentProvider : IUserAgentProvider + { + private readonly IHttpContextAccessor _httpContextAccessor; + + public AspNetCoreUserAgentProvider(IHttpContextAccessor httpContextAccessor) + { + _httpContextAccessor = httpContextAccessor; + } + + public string GetUserAgent() + { + return _httpContextAccessor.HttpContext.Request.Headers["User-Agent"].ToString(); + } + } +}