Fix #3068 - support microsites in .NET MAUI
This commit is contained in:
@ -0,0 +1,7 @@
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
public interface IServerStateManager
|
||||
{
|
||||
ServerState GetServerState(string siteKey);
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ namespace Oqtane.Infrastructure
|
||||
var config = context.RequestServices.GetService(typeof(IConfigManager)) as IConfigManager;
|
||||
string path = context.Request.Path.ToString();
|
||||
|
||||
|
||||
if (config.IsInstalled() && !path.StartsWith("/_blazor"))
|
||||
{
|
||||
// get alias (note that this also sets SiteState.Alias)
|
||||
@ -43,6 +44,14 @@ namespace Oqtane.Infrastructure
|
||||
});
|
||||
context.Items.Add(Constants.HttpContextSiteSettingsKey, sitesettings);
|
||||
|
||||
// handle first request to site
|
||||
var serverState = context.RequestServices.GetService(typeof(IServerStateManager)) as IServerStateManager;
|
||||
if (!serverState.GetServerState(alias.SiteKey).IsInitialized)
|
||||
{
|
||||
var sites = context.RequestServices.GetService(typeof(ISiteRepository)) as ISiteRepository;
|
||||
sites.InitializeSite(alias);
|
||||
}
|
||||
|
||||
// rewrite path by removing alias path prefix from reserved route (api,pages,files) requests for consistent routes
|
||||
if (!string.IsNullOrEmpty(alias.Path))
|
||||
{
|
||||
|
@ -5,9 +5,9 @@ namespace Oqtane.Infrastructure
|
||||
{
|
||||
public class ServerState
|
||||
{
|
||||
public int SiteId { get; set; }
|
||||
public string SiteKey { get; set; }
|
||||
public List<string> Assemblies { get; set; } = new List<string>();
|
||||
public List<Resource>Scripts { get; set; } = new List<Resource>();
|
||||
public bool IsMigrated { get; set; } = false;
|
||||
public bool IsInitialized { get; set; } = false;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using Oqtane.Models;
|
||||
namespace Oqtane.Infrastructure
|
||||
{
|
||||
// singleton
|
||||
public class ServerStateManager
|
||||
public class ServerStateManager : IServerStateManager
|
||||
{
|
||||
private List<ServerState> _serverStates { get; set; }
|
||||
|
||||
@ -14,36 +14,19 @@ namespace Oqtane.Infrastructure
|
||||
_serverStates = new List<ServerState>();
|
||||
}
|
||||
|
||||
public ServerState GetServerState(int siteId)
|
||||
public ServerState GetServerState(string siteKey)
|
||||
{
|
||||
var serverState = _serverStates.FirstOrDefault(item => item.SiteId == siteId);
|
||||
var serverState = _serverStates.FirstOrDefault(item => item.SiteKey == siteKey);
|
||||
if (serverState == null)
|
||||
{
|
||||
serverState = new ServerState();
|
||||
serverState.SiteId = siteId;
|
||||
serverState.SiteKey = siteKey;
|
||||
serverState.Assemblies = new List<string>();
|
||||
serverState.Scripts = new List<Resource>();
|
||||
return serverState;
|
||||
}
|
||||
else
|
||||
{
|
||||
return serverState;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetServerState(int siteId, ServerState serverState)
|
||||
{
|
||||
var serverstate = _serverStates.FirstOrDefault(item => item.SiteId == siteId);
|
||||
if (serverstate == null)
|
||||
{
|
||||
serverState.SiteId = siteId;
|
||||
serverState.IsInitialized = false;
|
||||
_serverStates.Add(serverState);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverstate.Assemblies = serverState.Assemblies;
|
||||
serverstate.Scripts = serverState.Scripts;
|
||||
}
|
||||
return serverState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Oqtane.Models;
|
||||
@ -57,7 +58,7 @@ namespace Oqtane.Infrastructure
|
||||
alias.BaseUrl = "";
|
||||
if (httpcontext.Request.Headers.ContainsKey("User-Agent") && httpcontext.Request.Headers["User-Agent"] == Shared.Constants.MauiUserAgent)
|
||||
{
|
||||
alias.BaseUrl = alias.Protocol + alias.Name;
|
||||
alias.BaseUrl = alias.Protocol + alias.Name.Replace("/" + alias.Path, "");
|
||||
}
|
||||
_siteState.Alias = alias;
|
||||
}
|
||||
|
Reference in New Issue
Block a user