add url mapping referrer
This commit is contained in:
@ -36,6 +36,7 @@ else
|
||||
<th>@Localizer["Url"]</th>
|
||||
<th>@Localizer["Requests"]</th>
|
||||
<th>@Localizer["Requested"]</th>
|
||||
<th>@Localizer["Referrer"]</th>
|
||||
</Header>
|
||||
<Row>
|
||||
<td><ActionLink Action="Edit" Text="Edit" Parameters="@($"id=" + context.UrlMappingId.ToString())" ResourceKey="Edit" /></td>
|
||||
@ -49,7 +50,8 @@ else
|
||||
</td>
|
||||
<td>@context.Requests</td>
|
||||
<td>@UtcToLocal(context.RequestedOn)</td>
|
||||
</Row>
|
||||
<td>@context.Referrer</td>
|
||||
</Row>
|
||||
</Pager>
|
||||
</TabPanel>
|
||||
<TabPanel Name="Settings" Heading="Settings" ResourceKey="Settings">
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -33,6 +33,11 @@ namespace Oqtane.Models
|
||||
/// </summary>
|
||||
public int Requests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last referrer to the Url (only set if linked to externally)
|
||||
/// </summary>
|
||||
public string Referrer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date when the url was first requested for the site
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user