SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite 1.2.0

dotnet add package SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite --version 1.2.0
                    
NuGet\Install-Package SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite --version 1.2.0
                    
#r "nuget: SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite&version=1.2.0
                    
Install as a Cake Tool

SimpleLinkShrinkLibrary

Overview

Publish new package version on NuGet

This library provides shared Razor UI and services for short links plus separate persistence packages. You call EnableShortlinks(...) to register the UI and application services, and then register persistence separately with EnableSqlServerPersistence(...) (SQL Server) or EnableSqlitePersistence(...) (SQLite).

Installation

1. NuGet

Install the main NuGet Package and the persistence package of your choice:

  • Main Package: SpiekerCodes.SimpleLinkShrinkLibrary.RCL
  • Database provider:
    • SQL Server: SpiekerCodes.SimpleLinkShrinkLibrary.SqlServer
    • SQLite: SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite

2. libman libraries

Install Bootstrap 5 and Toastify using libman:

{
  "version": "3.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "library": "bootstrap@5.3.8",
      "destination": "wwwroot/lib/bootstrap/"
    },
    {
      "library": "toastify-js@1.12.0",
      "destination": "wwwroot/lib/toastify-js/"
    }
  ]
}

Note: You need to enable "Restore on Build" in Visual Studio for libman to restore the libraries automatically.

Setup

1. Register Services (Program.cs)

Steps in this file:

  • Make sure, that you have AddControllersWithViews() called.
  • Add the shared Ui/services right after that and choose your persistence provider.

Using SQLite:

builder.Services.AddControllersWithViews();

builder.Services.EnableShortlinks(builder.Configuration)
    .EnableSqlitePersistence(builder.Configuration);

Using SQL Server:

builder.Services.AddControllersWithViews();

builder.Services.EnableShortlinks(builder.Configuration)
    .EnableSqlServerPersistence(builder.Configuration);

Note: If youre using Razor Pages, call "AddControllersWithViews()" additionally to "AddRazorPages()". MVC is necessary for this library to work. You also need to map the default controller route in app.MapDefaultControllerRoute().

[...]
builder.Services.AddRazorPages();
builder.Services.AddControllersWithViews();
[...]
app.MapStaticAssets();
app.MapRazorPages().WithStaticAssets();
app.MapDefaultControllerRoute().WithStaticAssets();
[...]

2. Specify Connection Strings

Ensure your appsettings.json includes the appropriate connection string:

  • For SQLite:
    {
      "ConnectionStrings": {
        "ShortlinkDbConnectionString": "Data Source=Shortlinks.db"
      }
    }
    
  • For SQL Server:
    {
      "ConnectionStrings": {
        "ShortlinkDbConnectionString": "Data Source={MyServerAddress};Initial Catalog={MyDatabaseName};Integrated Security=True;"
      }
    }
    

Configure alias length and expiration in appsettings.json:

{
  "ShortlinkSettings": {
    "AliasLength": 5,
    "ExpirationSpan": "5.00:00:00"
  }
}

4. Static assets and layout

Add Bootstrap and Toastify CSS to your _Layout.cshtml:

[...]
    <link rel="stylesheet" href="~/lib/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/lib/toastify-js/toastify.min.css" />
</head>
[...]

Reference the partial view _ShortlinkMenu in your navigation bar:

[...]
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
    <li class="nav-item">
        <a id="homeIndex" class="nav-link" asp-controller="Home" asp-action="Index">Start</a>
    </li>

    @* Adding partial view *@
    <partial name="_ShortlinkMenu" />
</ul>
[...]

Add Bootstrap and Toastify scripts at the end of _Layout.cshtml:

    [...]
    <script src="~/lib/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="~/lib/toastify-js/toastify.min.js"></script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>

5. Support reverse proxies (optional)

If your application runs behind a reverse proxy (e.g., Nginx, Apache, Traefik), configure forwarded headers to ensure the library generates correct public-facing URLs for short links. Without this configuration, the library may use the internal request URL instead of the public URL.

  1. Add enableReverseProxySupport: true to your EnableShortlinks call in Program.cs to configure forwarded headers.
  2. Call app.UseForwardedHeaders(); immediately after var app = builder.Build(); in Program.cs to enable header forwarding.

If you are using Traefik as reverse proxy via Docker Compose (example), make sure to set the X-Forwarded-Proto header in your Traefik configuration:

services:
  myapp:
    image: myapp:latest
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.myapp.rule=Host(`myapp.example.com`)"
      - "traefik.http.routers.myapp.entrypoints=web"
      - "traefik.http.middlewares.myapp-headers.headers.customrequestheaders.X-Forwarded-Proto=https"
      - "traefik.http.routers.myapp.middlewares=myapp-headers"
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.0 217 2/26/2026
1.1.0 324 12/17/2025
1.0.0 422 11/19/2025
1.0.0-alpha.4 379 11/18/2025
1.0.0-alpha.3 372 11/18/2025
1.0.0-alpha.2 372 11/18/2025
1.0.0-alpha.1 376 11/18/2025