diff --git a/Oqtane.Client/App.razor b/Oqtane.Client/App.razor
index 1a834052..82a0b24a 100644
--- a/Oqtane.Client/App.razor
+++ b/Oqtane.Client/App.razor
@@ -4,37 +4,44 @@
@if (_initialized)
{
-
- @if (!_installation.Success)
+ @if (!_installation.Success)
+ {
+
+ }
+ else
+ {
+ @if (string.IsNullOrEmpty(_installation.Message))
{
-
- }
- else
- {
- @if (string.IsNullOrEmpty(_installation.Message))
- {
+
- }
- else
- {
-
- @_installation.Message
-
- }
+
}
-
+ else
+ {
+
+ @_installation.Message
+
+ }
+ }
}
@code {
+ [Parameter]
+ public string AntiForgeryToken { get; set; }
+
+ [Parameter]
+ public string Runtime { get; set; }
+
+ [Parameter]
+ public string RenderMode { get; set; }
+
private bool _initialized = false;
private string _display = "display: none;";
private Installation _installation = new Installation { Success = false, Message = "" };
- private string Runtime = "";
- private string RenderMode = "";
private PageState PageState { get; set; }
@@ -44,6 +51,7 @@
if (_installation.Alias != null)
{
SiteState.Alias = _installation.Alias;
+ SiteState.AntiForgeryToken = AntiForgeryToken;
}
else
{
@@ -56,10 +64,15 @@
{
if (firstRender)
{
- var interop = new Interop(JSRuntime);
- SiteState.AntiForgeryToken = await interop.GetElementByName(Constants.RequestVerificationToken);
- Runtime = await interop.GetElementByName("app_runtime");
- RenderMode = await interop.GetElementByName("app_rendermode");
+ if (string.IsNullOrEmpty(AntiForgeryToken))
+ {
+ // parameter values are not set when running on WebAssembly (seems to be a .NET 5 bug) - need to retrieve using JSInterop
+ var interop = new Interop(JSRuntime);
+ AntiForgeryToken = await interop.GetElementByName(Constants.RequestVerificationToken);
+ SiteState.AntiForgeryToken = AntiForgeryToken;
+ Runtime = await interop.GetElementByName("app_runtime");
+ RenderMode = await interop.GetElementByName("app_rendermode");
+ }
_display = "";
StateHasChanged();
}
diff --git a/Oqtane.Client/UI/SiteRouter.razor b/Oqtane.Client/UI/SiteRouter.razor
index 321581db..8f73a00b 100644
--- a/Oqtane.Client/UI/SiteRouter.razor
+++ b/Oqtane.Client/UI/SiteRouter.razor
@@ -55,7 +55,7 @@
protected override async Task OnParametersSetAsync()
{
- if (PageState == null && !string.IsNullOrEmpty(Runtime))
+ if (PageState == null)
{
await Refresh();
}
diff --git a/Oqtane.Server/Pages/_Host.cshtml b/Oqtane.Server/Pages/_Host.cshtml
index 5352d69c..7229575b 100644
--- a/Oqtane.Server/Pages/_Host.cshtml
+++ b/Oqtane.Server/Pages/_Host.cshtml
@@ -20,7 +20,7 @@
@(Html.AntiForgeryToken())
-
+
diff --git a/Oqtane.Server/Pages/_Host.cshtml.cs b/Oqtane.Server/Pages/_Host.cshtml.cs
index c0333760..499f00ad 100644
--- a/Oqtane.Server/Pages/_Host.cshtml.cs
+++ b/Oqtane.Server/Pages/_Host.cshtml.cs
@@ -12,6 +12,7 @@ using Oqtane.Repository;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Mvc.Rendering;
+using Microsoft.AspNetCore.Antiforgery;
namespace Oqtane.Pages
{
@@ -21,19 +22,18 @@ namespace Oqtane.Pages
private readonly ITenantManager _tenantManager;
private readonly ILocalizationManager _localizationManager;
private readonly ILanguageRepository _languages;
+ private readonly IAntiforgery _antiforgery;
- public HostModel(
- IConfiguration configuration,
- ITenantManager tenantManager,
- ILocalizationManager localizationManager,
- ILanguageRepository languages)
+ public HostModel(IConfiguration configuration, ITenantManager tenantManager, ILocalizationManager localizationManager, ILanguageRepository languages, IAntiforgery antiforgery)
{
_configuration = configuration;
_tenantManager = tenantManager;
_localizationManager = localizationManager;
_languages = languages;
+ _antiforgery = antiforgery;
}
+ public string AntiForgeryToken = "";
public string Runtime = "Server";
public RenderMode RenderMode = RenderMode.Server;
public string HeadResources = "";
@@ -41,6 +41,8 @@ namespace Oqtane.Pages
public void OnGet()
{
+ AntiForgeryToken = _antiforgery.GetAndStoreTokens(HttpContext).RequestToken;
+
if (_configuration.GetSection("Runtime").Exists())
{
Runtime = _configuration.GetSection("Runtime").Value;
@@ -50,7 +52,7 @@ namespace Oqtane.Pages
{
RenderMode = (RenderMode)Enum.Parse(typeof(RenderMode), _configuration.GetSection("RenderMode").Value, true);
}
-
+
var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies();
foreach (Assembly assembly in assemblies)
{