url mapping improvements
This commit is contained in:
parent
e0044658f9
commit
4f16cd2d01
@ -8,9 +8,12 @@
|
|||||||
<form @ref="form" class="@(validated ? "was-validated" : "needs-validation")" novalidate>
|
<form @ref="form" class="@(validated ? "was-validated" : "needs-validation")" novalidate>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row mb-1 align-items-center">
|
<div class="row mb-1 align-items-center">
|
||||||
<Label Class="col-sm-3" For="url" HelpText="The fully qualified Url for this site" ResourceKey="Url">Url:</Label>
|
<Label Class="col-sm-3" For="url" HelpText="An absolute Url for this site" ResourceKey="Url">Url:</Label>
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<input id="url" class="form-control" @bind="@_url" maxlength="500" required />
|
<div class="input-group">
|
||||||
|
<input id="url" class="form-control" @bind="@_url" maxlength="500" required />
|
||||||
|
<button type="button" class="btn btn-primary" @onclick="GenerateUrl">@Localizer["Generate"]</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-1 align-items-center">
|
<div class="row mb-1 align-items-center">
|
||||||
@ -49,43 +52,57 @@
|
|||||||
_url = (!_url.StartsWith("http")) ? url + _url : _url;
|
_url = (!_url.StartsWith("http")) ? url + _url : _url;
|
||||||
|
|
||||||
_mappedurl = _mappedurl.Replace(url, "");
|
_mappedurl = _mappedurl.Replace(url, "");
|
||||||
_mappedurl = (_mappedurl.StartsWith("/")) ? _mappedurl.Substring(1) : _mappedurl;
|
_mappedurl = (_mappedurl.StartsWith("/") && _mappedurl != "/") ? _mappedurl.Substring(1) : _mappedurl;
|
||||||
|
|
||||||
if (_url.StartsWith(url))
|
if (_url.StartsWith(url))
|
||||||
{
|
{
|
||||||
var urlmapping = new UrlMapping();
|
var urlmapping = new UrlMapping();
|
||||||
urlmapping.SiteId = PageState.Site.SiteId;
|
urlmapping.SiteId = PageState.Site.SiteId;
|
||||||
urlmapping.Url = new Route(_url, PageState.Alias.Path).PagePath;
|
urlmapping.Url = new Route(_url, PageState.Alias.Path).PagePath;
|
||||||
urlmapping.MappedUrl = _mappedurl;
|
urlmapping.MappedUrl = _mappedurl;
|
||||||
urlmapping.Requests = 0;
|
urlmapping.Requests = 0;
|
||||||
urlmapping.CreatedOn = DateTime.UtcNow;
|
urlmapping.CreatedOn = DateTime.UtcNow;
|
||||||
urlmapping.RequestedOn = DateTime.UtcNow;
|
urlmapping.RequestedOn = DateTime.UtcNow;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
urlmapping = await UrlMappingService.AddUrlMappingAsync(urlmapping);
|
urlmapping = await UrlMappingService.AddUrlMappingAsync(urlmapping);
|
||||||
await logger.LogInformation("UrlMapping Saved {UrlMapping}", urlmapping);
|
await logger.LogInformation("UrlMapping Saved {UrlMapping}", urlmapping);
|
||||||
NavigationManager.NavigateTo(NavigateUrl());
|
NavigationManager.NavigateTo(NavigateUrl());
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
await logger.LogError(ex, "Error Saving UrlMapping {UrlMapping} {Error}", urlmapping, ex.Message);
|
await logger.LogError(ex, "Error Saving UrlMapping {UrlMapping} {Error}", urlmapping, ex.Message);
|
||||||
AddModuleMessage(Localizer["Error.SaveUrlMapping"], MessageType.Error);
|
AddModuleMessage(Localizer["Error.SaveUrlMapping"], MessageType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddModuleMessage(Localizer["Message.SaveUrlMapping"], MessageType.Warning);
|
AddModuleMessage(Localizer["Message.SaveUrlMapping"], MessageType.Warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddModuleMessage(Localizer["Message.DuplicateUrlMapping"], MessageType.Warning);
|
AddModuleMessage(Localizer["Message.DuplicateUrlMapping"], MessageType.Warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning);
|
AddModuleMessage(SharedLocalizer["Message.InfoRequired"], MessageType.Warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void GenerateUrl()
|
||||||
|
{
|
||||||
|
var url = PageState.Uri.Scheme + "://" + PageState.Uri.Authority + "/";
|
||||||
|
url = url + (!string.IsNullOrEmpty(PageState.Alias.Path) ? PageState.Alias.Path + "/" : "");
|
||||||
|
|
||||||
|
var chars = "abcdefghijklmnopqrstuvwxyz";
|
||||||
|
Random rnd = new Random();
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
url += chars.Substring(rnd.Next(0, chars.Length - 1), 1);
|
||||||
|
}
|
||||||
|
_url = url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
url = url + (!string.IsNullOrEmpty(PageState.Alias.Path) ? PageState.Alias.Path + "/" : "");
|
url = url + (!string.IsNullOrEmpty(PageState.Alias.Path) ? PageState.Alias.Path + "/" : "");
|
||||||
|
|
||||||
_mappedurl = _mappedurl.Replace(url, "");
|
_mappedurl = _mappedurl.Replace(url, "");
|
||||||
_mappedurl = (_mappedurl.StartsWith("/")) ? _mappedurl.Substring(1) : _mappedurl;
|
_mappedurl = (_mappedurl.StartsWith("/") && _mappedurl != "/") ? _mappedurl.Substring(1) : _mappedurl;
|
||||||
|
|
||||||
var urlmapping = await UrlMappingService.GetUrlMappingAsync(_urlmappingid);
|
var urlmapping = await UrlMappingService.GetUrlMappingAsync(_urlmappingid);
|
||||||
urlmapping.MappedUrl = _mappedurl;
|
urlmapping.MappedUrl = _mappedurl;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<root>
|
<root>
|
||||||
<!--
|
<!--
|
||||||
Microsoft ResX Schema
|
Microsoft ResX Schema
|
||||||
@ -121,10 +121,10 @@
|
|||||||
<value>Redirect To:</value>
|
<value>Redirect To:</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MappedUrl.HelpText" xml:space="preserve">
|
<data name="MappedUrl.HelpText" xml:space="preserve">
|
||||||
<value>A relative or absolute Url where the user will be redirected</value>
|
<value>A relative or absolute Url where the user will be redirected. Use "/" for site root path.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Url.HelpText" xml:space="preserve">
|
<data name="Url.HelpText" xml:space="preserve">
|
||||||
<value>An absolute Url identifying a path to a specific page in the site</value>
|
<value>An absolute Url for this site</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Url.Text" xml:space="preserve">
|
<data name="Url.Text" xml:space="preserve">
|
||||||
<value>Url:</value>
|
<value>Url:</value>
|
||||||
@ -141,4 +141,7 @@
|
|||||||
<data name="Message.SaveUrlMapping" xml:space="preserve">
|
<data name="Message.SaveUrlMapping" xml:space="preserve">
|
||||||
<value>The Url must belong to the current site</value>
|
<value>The Url must belong to the current site</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Generate" xml:space="preserve">
|
||||||
|
<value>Generate</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -121,7 +121,7 @@
|
|||||||
<value>Redirect To:</value>
|
<value>Redirect To:</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MappedUrl.HelpText" xml:space="preserve">
|
<data name="MappedUrl.HelpText" xml:space="preserve">
|
||||||
<value>A relative or absolute Url where the user will be redirected</value>
|
<value>A relative or absolute Url where the user will be redirected. Use "/" for site root path.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Url.HelpText" xml:space="preserve">
|
<data name="Url.HelpText" xml:space="preserve">
|
||||||
<value>A relative Url identifying a path to a specific page in the site</value>
|
<value>A relative Url identifying a path to a specific page in the site</value>
|
||||||
|
@ -343,7 +343,7 @@
|
|||||||
var urlMapping = await UrlMappingService.GetUrlMappingAsync(site.SiteId, route.PagePath);
|
var urlMapping = await UrlMappingService.GetUrlMappingAsync(site.SiteId, route.PagePath);
|
||||||
if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl))
|
if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl))
|
||||||
{
|
{
|
||||||
var url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + "/" + urlMapping.MappedUrl + route.Query;
|
var url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + (!urlMapping.MappedUrl.StartsWith("/") ? "/" : "") + urlMapping.MappedUrl + ((!urlMapping.MappedUrl.Contains("?")) ? route.Query : "");
|
||||||
NavigationManager.NavigateTo(url, false);
|
NavigationManager.NavigateTo(url, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@
|
|||||||
if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl))
|
if (urlMapping != null && !string.IsNullOrEmpty(urlMapping.MappedUrl))
|
||||||
{
|
{
|
||||||
// redirect to mapped url
|
// redirect to mapped url
|
||||||
var url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + "/" + urlMapping.MappedUrl;
|
var url = (urlMapping.MappedUrl.StartsWith("http")) ? urlMapping.MappedUrl : route.SiteUrl + (!urlMapping.MappedUrl.StartsWith("/") ? "/" : "") + urlMapping.MappedUrl + ((!urlMapping.MappedUrl.Contains("?")) ? route.Query : "");
|
||||||
NavigationManager.NavigateTo(url, true);
|
NavigationManager.NavigateTo(url, true);
|
||||||
}
|
}
|
||||||
else // no url mapping exists
|
else // no url mapping exists
|
||||||
|
Loading…
x
Reference in New Issue
Block a user