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
<PackageReference Include="SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite" Version="1.2.0" />
<PackageVersion Include="SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite" Version="1.2.0" />
<PackageReference Include="SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite" />
paket add SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite --version 1.2.0
#r "nuget: SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite, 1.2.0"
#:package SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite@1.2.0
#addin nuget:?package=SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite&version=1.2.0
#tool nuget:?package=SpiekerCodes.SimpleLinkShrinkLibrary.Sqlite&version=1.2.0
SimpleLinkShrinkLibrary
Overview
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
- SQL Server:
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;" } }
3. Configure Shortlink Settings
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.
- Add
enableReverseProxySupport: trueto yourEnableShortlinkscall inProgram.csto configure forwarded headers. - Call
app.UseForwardedHeaders();immediately aftervar app = builder.Build();inProgram.csto 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 | Versions 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. |
-
net10.0
-
net8.0
-
net9.0
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 |