JCTools.Shortener
1.1.1
See the version list below for details.
dotnet add package JCTools.Shortener --version 1.1.1
NuGet\Install-Package JCTools.Shortener -Version 1.1.1
<PackageReference Include="JCTools.Shortener" Version="1.1.1" />
paket add JCTools.Shortener --version 1.1.1
#r "nuget: JCTools.Shortener, 1.1.1"
// Install JCTools.Shortener as a Cake Addin #addin nuget:?package=JCTools.Shortener&version=1.1.1 // Install JCTools.Shortener as a Cake Tool #tool nuget:?package=JCTools.Shortener&version=1.1.1
JCTools.Shortener
A simple links shortener for include in .net core projects.
Allows add support for create and manage random and unique short links. Its short links are ready for share link to the features or pages of your site.
The short links are created with the letters of the alphabet of the english language and the numerals 0-9, a total use 62 distinct characters.
This characters can will generate more of 57 billions of distinct combinations.
By default, the short links have a longitude between 2 and 6 characters; but, too can configure this longitude.
The longitude and the characters can was changed in the service initialization into the startup class.
Usage
- Add the package JCTools.Shortener to your project.
dotnet add package JCTools.Shortener -v 1.1.1
- Implement the interface IDatabaseContext in your database contest
public class DataContext : Microsoft.EntityFrameworkCore.DbContext, JCTools.Shortener.Settings.IDatabaseContext
{
public DataContext(DbContextOptions<DataContext> options)
: base(options)
{ }
/// <summary>
/// the short links collection
/// </summary>
public DbSet<ShortLink> ShortLinks { get; set; }
}
- Add the namespace JCTools.Shortener to the startup class
using JCTools.Shortener;
- Configure the shortener service into the ConfigureServices method of the Startup class
services.AddLinksShortener<DbContext>();
- Inject the JCTools.Shortener.Services.ILinkGenerator service
public class OtherController : Controller
{
private readonly ILinkGenerator _shortenerService;
public OtherController(ILinkGenerator shortenerService)
{
...
this._shortenerService = shortenerService;
...
}
...
}
- Generate the short link
...
// only generate a token
var token = await _shortenerService.GenerateTokenAsync();
// Generate a new entry with a short link
var realUrl = "https://www.google.com/doodles/"
var link = await _shortenerServices.GenerateAsync(realUrl);
// Generate a new entry with a short link and store into the database
var other = await _shortenerServices. GenerateAndSaveAsync(realUrl);
...
Other settings
In the configuration of the Shortener services into the ConfigureServices method of the Startup class, is possible change the default configuration of the short links.
...
services.AddLinksShortener<DbContext>(o => {
// 1. Change the collection of the characters to be used for generate the short links
o.ValidCharacters = "1234567890-_qwerty";
// 2. The min longitude (default 2) of the short links
o.MinLength = 3;
// 3. The max longitude (default 6) of the short links
o.MaxLength = 10;
// 4. By default, the access to the redirection action is anonymous
// It's possible change using a authorization policy
o.ConfigurePolicy = p => {
p.RequireAuthenticatedUser();
p.RequireRole("admin");
...
};
});
...
License
This package is released under the MIT license
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.EntityFrameworkCore (>= 3.1.10)
-
net5.0
- Microsoft.EntityFrameworkCore (>= 3.1.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.