diff --git a/Oqtane.Client/Modules/Admin/UrlMappings/Index.razor b/Oqtane.Client/Modules/Admin/UrlMappings/Index.razor
index 554213fa..ae12713b 100644
--- a/Oqtane.Client/Modules/Admin/UrlMappings/Index.razor
+++ b/Oqtane.Client/Modules/Admin/UrlMappings/Index.razor
@@ -36,6 +36,7 @@ else
@Localizer["Url"] |
@Localizer["Requests"] |
@Localizer["Requested"] |
+ @Localizer["Referrer"] |
|
@@ -49,7 +50,8 @@ else
@context.Requests |
@UtcToLocal(context.RequestedOn) |
-
+ @context.Referrer |
+
diff --git a/Oqtane.Server/Components/App.razor b/Oqtane.Server/Components/App.razor
index 6276eea0..fe668866 100644
--- a/Oqtane.Server/Components/App.razor
+++ b/Oqtane.Server/Components/App.razor
@@ -294,8 +294,11 @@
private void HandlePageNotFound(Site site, Page page, Route route)
{
+ // referrer will only be set if the link originated externally
+ string referrer = (Context.Request.Headers[HeaderNames.Referer] != StringValues.Empty) ? Context.Request.Headers[HeaderNames.Referer] : "";
+
// page not found - look for url mapping
- var urlMapping = UrlMappingRepository.GetUrlMapping(site.SiteId, route.PagePath);
+ var urlMapping = UrlMappingRepository.GetUrlMapping(site.SiteId, route.PagePath, referrer);
if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl))
{
// redirect to mapped url
diff --git a/Oqtane.Server/Migrations/Tenant/10000203_AddUrlMappingReferrer.cs b/Oqtane.Server/Migrations/Tenant/10000203_AddUrlMappingReferrer.cs
new file mode 100644
index 00000000..217b0d4c
--- /dev/null
+++ b/Oqtane.Server/Migrations/Tenant/10000203_AddUrlMappingReferrer.cs
@@ -0,0 +1,28 @@
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Oqtane.Databases.Interfaces;
+using Oqtane.Migrations.EntityBuilders;
+using Oqtane.Repository;
+
+namespace Oqtane.Migrations.Tenant
+{
+ [DbContext(typeof(TenantDBContext))]
+ [Migration("Tenant.10.00.02.03")]
+ public class AddUrlMappingReferrer : MultiDatabaseMigration
+ {
+ public AddUrlMappingReferrer(IDatabase database) : base(database)
+ {
+ }
+
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ var urlMappingEntityBuilder = new UrlMappingEntityBuilder(migrationBuilder, ActiveDatabase);
+ urlMappingEntityBuilder.AddStringColumn("Referrer", 2048);
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ // not implemented
+ }
+ }
+}
diff --git a/Oqtane.Server/Repository/UrlMappingRepository.cs b/Oqtane.Server/Repository/UrlMappingRepository.cs
index 9c2efbb6..b86b68b8 100644
--- a/Oqtane.Server/Repository/UrlMappingRepository.cs
+++ b/Oqtane.Server/Repository/UrlMappingRepository.cs
@@ -14,6 +14,7 @@ namespace Oqtane.Repository
UrlMapping GetUrlMapping(int urlMappingId);
UrlMapping GetUrlMapping(int urlMappingId, bool tracking);
UrlMapping GetUrlMapping(int siteId, string url);
+ UrlMapping GetUrlMapping(int siteId, string url, string referrer);
void DeleteUrlMapping(int urlMappingId);
int DeleteUrlMappings(int siteId, int age);
}
@@ -78,6 +79,11 @@ namespace Oqtane.Repository
}
public UrlMapping GetUrlMapping(int siteId, string url)
+ {
+ return GetUrlMapping(siteId, url, "");
+ }
+
+ public UrlMapping GetUrlMapping(int siteId, string url, string referrer)
{
using var db = _dbContextFactory.CreateDbContext();
url = (url.StartsWith("/")) ? url.Substring(1) : url;
@@ -93,6 +99,7 @@ namespace Oqtane.Repository
urlMapping.Url = url;
urlMapping.MappedUrl = "";
urlMapping.Requests = 1;
+ urlMapping.Referrer = referrer;
urlMapping.CreatedOn = DateTime.UtcNow;
urlMapping.RequestedOn = DateTime.UtcNow;
try
@@ -109,6 +116,10 @@ namespace Oqtane.Repository
{
urlMapping.Requests += 1;
urlMapping.RequestedOn = DateTime.UtcNow;
+ if (!string.IsNullOrEmpty(referrer))
+ {
+ urlMapping.Referrer = referrer;
+ }
urlMapping = UpdateUrlMapping(urlMapping);
}
return urlMapping;
diff --git a/Oqtane.Shared/Models/UrlMapping.cs b/Oqtane.Shared/Models/UrlMapping.cs
index b5a15384..fb00e709 100644
--- a/Oqtane.Shared/Models/UrlMapping.cs
+++ b/Oqtane.Shared/Models/UrlMapping.cs
@@ -33,6 +33,11 @@ namespace Oqtane.Models
///
public int Requests { get; set; }
+ ///
+ /// Last referrer to the Url (only set if linked to externally)
+ ///
+ public string Referrer { get; set; }
+
///
/// Date when the url was first requested for the site
///