Introduced GetRequiredUmbracoContext extension on IUmbracoContextAccessor
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
public static class UmbracoContextAccessorExtensions
|
||||
{
|
||||
public static IUmbracoContext GetRequiredUmbracoContext(this IUmbracoContextAccessor umbracoContextAccessor)
|
||||
{
|
||||
if (umbracoContextAccessor == null) throw new ArgumentNullException(nameof(umbracoContextAccessor));
|
||||
|
||||
var umbracoContext = umbracoContextAccessor.UmbracoContext;
|
||||
|
||||
if(umbracoContext is null) throw new InvalidOperationException("UmbracoContext is null");
|
||||
|
||||
return umbracoContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,6 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
private bool HasMachineKey()
|
||||
{
|
||||
return _machineKeyConfig.HasMachineKey;
|
||||
// var section = (MachineKeySection) WebConfigurationManager.GetSection("system.web/machineKey");
|
||||
// return section.ElementInformation.Source != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Umbraco.Web.Install.InstallSteps
|
||||
|
||||
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
||||
{
|
||||
var security = _umbracoContextAccessor.UmbracoContext.Security;
|
||||
var security = _umbracoContextAccessor.GetRequiredUmbracoContext().Security;
|
||||
if (security.IsAuthenticated() == false && _globalSettings.ConfigurationStatus.IsNullOrWhiteSpace())
|
||||
{
|
||||
security.PerformLogin(-1);
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
public static HttpContextBase GetRequiredHttpContext(this IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
if (httpContextAccessor == null) throw new ArgumentNullException(nameof(httpContextAccessor));
|
||||
var httpContext = httpContextAccessor.HttpContext;
|
||||
|
||||
if(httpContext is null) throw new InvalidOperationException("HttpContext is null");
|
||||
|
||||
Reference in New Issue
Block a user