Added more aspnet core implementation of interfaces

This commit is contained in:
Bjarke Berg
2020-02-27 11:10:43 +01:00
parent 178a172be1
commit 2a16ebee0b
5 changed files with 65 additions and 9 deletions

View File

@@ -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);

View File

@@ -1,6 +1,4 @@
using System;
using System.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
namespace Umbraco.Web.BackOffice.AspNetCore
{

View File

@@ -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;
}
}

View File

@@ -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();
}
}
}

View File

@@ -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();
}
}
}