fix logic issue in url mapping, improve 404 handling, add property change component notifications
This commit is contained in:
parent
683ad8959a
commit
042083c0e7
|
@ -258,10 +258,15 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
await LogService.Log(null, null, user.UserId, GetType().AssemblyQualifiedName, Utilities.GetTypeNameLastSegment(GetType().AssemblyQualifiedName, 1), LogFunction.Security, LogLevel.Error, null, "Page Does Not Exist Or User Is Not Authorized To View Page {Path}", route.PagePath);
|
||||
if (route.PagePath != "")
|
||||
if (route.PagePath != "404")
|
||||
{
|
||||
// redirect to home page
|
||||
await LogService.Log(null, null, user.UserId, "SiteRouter", "SiteRouter", LogFunction.Other, LogLevel.Information, null, "Page Path /{Path} Does Not Exist Or User Is Not Authorized To View", route.PagePath);
|
||||
// redirect to 404 page
|
||||
NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "404", ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
// redirect to home page as a fallback
|
||||
NavigationManager.NavigateTo(Utilities.NavigateUrl(SiteState.Alias.Path, "", ""));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ namespace Oqtane.Pages
|
|||
}
|
||||
|
||||
var page = _pages.GetPage(route.PagePath, site.SiteId);
|
||||
if (page != null & !page.IsDeleted)
|
||||
if (page != null && !page.IsDeleted)
|
||||
{
|
||||
// set page title
|
||||
if (!string.IsNullOrEmpty(page.Title))
|
||||
|
@ -182,6 +182,14 @@ namespace Oqtane.Pages
|
|||
url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + "/" + urlMapping.MappedUrl;
|
||||
return RedirectPermanent(url);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (route.PagePath != "404")
|
||||
{
|
||||
_logger.Log(LogLevel.Information, "Host", LogFunction.Other, "Page Path /{Path} Does Not Exist", route.PagePath);
|
||||
return RedirectPermanent(route.SiteUrl + "/404");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// include global resources
|
||||
|
|
|
@ -390,6 +390,32 @@ namespace Oqtane.Repository
|
|||
}
|
||||
}
|
||||
});
|
||||
pageTemplates.Add(new PageTemplate
|
||||
{
|
||||
Name = "Not Found",
|
||||
Parent = "",
|
||||
Path = "404",
|
||||
Icon = Icons.X,
|
||||
IsNavigation = false,
|
||||
IsPersonalizable = false,
|
||||
PagePermissions = new List<Permission>
|
||||
{
|
||||
new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
||||
new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||
}.EncodePermissions(),
|
||||
PageTemplateModules = new List<PageTemplateModule>
|
||||
{
|
||||
new PageTemplateModule { ModuleDefinitionName = "Oqtane.Modules.HtmlText, Oqtane.Client", Title = "Not Found", Pane = PaneNames.Admin,
|
||||
ModulePermissions = new List<Permission> {
|
||||
new Permission(PermissionNames.View, RoleNames.Everyone, true),
|
||||
new Permission(PermissionNames.View, RoleNames.Admin, true),
|
||||
new Permission(PermissionNames.Edit, RoleNames.Admin, true)
|
||||
}.EncodePermissions(),
|
||||
Content = "<p>The page you requested does not exist.</p>"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// admin pages
|
||||
pageTemplates.Add(new PageTemplate
|
||||
|
|
101
Oqtane.Shared/Shared/PropertyDictionary.cs
Normal file
101
Oqtane.Shared/Shared/PropertyDictionary.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Dynamic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Oqtane.Shared
|
||||
{
|
||||
public class PropertyDictionary : DynamicObject, IDictionary<string, object>, INotifyPropertyChanged
|
||||
{
|
||||
readonly IDictionary<string, object> _dictionary = new Dictionary<string, object>();
|
||||
|
||||
public void Add(KeyValuePair<string, object> item)
|
||||
{
|
||||
_dictionary.Add(item.Key, item.Value);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_dictionary.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(KeyValuePair<string, object> item)
|
||||
{
|
||||
return _dictionary.Contains(item);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
|
||||
{
|
||||
_dictionary.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public bool Remove(KeyValuePair<string, object> item)
|
||||
{
|
||||
return _dictionary.Remove(item);
|
||||
}
|
||||
|
||||
public int Count => _dictionary.Count;
|
||||
public bool IsReadOnly => _dictionary.IsReadOnly;
|
||||
|
||||
public override bool TryGetMember(GetMemberBinder binder, out object result)
|
||||
{
|
||||
if (!_dictionary.TryGetValue(binder.Name, out result)) result = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool TrySetMember(SetMemberBinder binder, object value)
|
||||
{
|
||||
_dictionary[binder.Name] = value;
|
||||
OnPropertyChanged(binder.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
|
||||
{
|
||||
return _dictionary.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable)_dictionary).GetEnumerator();
|
||||
}
|
||||
|
||||
public void Add(string key, object value)
|
||||
{
|
||||
_dictionary.Add(key, value);
|
||||
}
|
||||
|
||||
public bool ContainsKey(string key)
|
||||
{
|
||||
return _dictionary.ContainsKey(key);
|
||||
}
|
||||
|
||||
public bool Remove(string key)
|
||||
{
|
||||
return _dictionary.Remove(key);
|
||||
}
|
||||
|
||||
public bool TryGetValue(string key, out object value)
|
||||
{
|
||||
return _dictionary.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public object this[string key]
|
||||
{
|
||||
get => _dictionary[key];
|
||||
set => _dictionary[key] = value;
|
||||
}
|
||||
|
||||
public ICollection<string> Keys => _dictionary.Keys;
|
||||
|
||||
public ICollection<object> Values => _dictionary.Values;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,5 +9,10 @@ namespace Oqtane.Shared
|
|||
public string AntiForgeryToken { get; set; } // passed from server for use in service calls on client
|
||||
public string AuthorizationToken { get; set; } // passed from server for use in service calls on client
|
||||
public string RemoteIPAddress { get; set; } // passed from server as cannot be reliable retrieved on client
|
||||
|
||||
|
||||
private dynamic _properties;
|
||||
public dynamic Properties => _properties ?? (_properties = new PropertyDictionary());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user