JCTools.Shortener 1.1.2

Install-Package JCTools.Shortener -Version 1.1.2
dotnet add package JCTools.Shortener --version 1.1.2
<PackageReference Include="JCTools.Shortener" Version="1.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JCTools.Shortener --version 1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JCTools.Shortener, 1.1.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install JCTools.Shortener as a Cake Addin
#addin nuget:?package=JCTools.Shortener&version=1.1.2

// Install JCTools.Shortener as a Cake Tool
#tool nuget:?package=JCTools.Shortener&version=1.1.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

JCTools.Shortener

v1.1.2 .net core 3.1 .net 5.0

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

  1. Add the package JCTools.Shortener to your project.
    dotnet add package JCTools.Shortener -v 1.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; }

    }
  1. Add the namespace JCTools.Shortener to the startup class
    using JCTools.Shortener;
  1. Configure the shortener service into the ConfigureServices method of the Startup class
    services.AddLinksShortener<DbContext>();
  1. Inject the JCTools.Shortener.Services.ILinkGenerator service
    public class OtherController : Controller
    {
        private readonly ILinkGenerator _shortenerService;

        public OtherController(ILinkGenerator shortenerService)
        {
            ...
    
            this._shortenerService = shortenerService;
    
            ...
        }

        ...

    }
  1. 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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2 175 12/21/2020
1.1.1 148 12/21/2020
1.1.0 151 12/21/2020
1.0.8 265 6/20/2020
1.0.6 225 3/14/2020