百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

Shortener

> 数据库
开源

在 ASP.NET Core 和 Actor Model 中使用缩短 URL 服务

178 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

在 ASP.NET Core 和 Actor Model 中使用缩短 URL 服务

Shortener Service

This is a URL shortener service implemented in ASP.NET Core and MongoDB. It allows users to shorten long URLs into shorter, more manageable ones.

Features

  • Shorten long URLs into unique, shortcodes
  • Redirect users from short URLs to original long URLs
  • MongoDB database for persisting data
  • RESTful API for easy integration with other applications
  • Metrics

Technologies Used

  • ASP.NET Core
  • MongoDB
  • C#
  • Minimal APIs
  • InMemory Cache
  • Open Telemetry
  • Prometheus

Installation

  1. Clone the repository:
bash
git clone https://github.com/thisisnabi/Shortener.git

Give a Star! ⭐

If you find this project helpful or interesting, please consider giving it a star on GitHub. It helps support the project and recognizes the contributors.

Getting Started

To start with the URL shortener service, follow the installation instructions in the Installation section above. Once the service is up and running, you can begin using the API endpoints to shorten URLs, track statistics, and manage your shortened links.

Problem

The primary problem with long URLs is their lack of user-friendliness and practicality in various contexts. Long URLs can be cumbersome to manually input, difficult to remember, and can exceed character limitations imposed by certain platforms, such as social media posts or text messages.

This can result in broken links, truncated URLs, or user frustration when attempting to share or access lengthy URLs in constrained environments.

Solution

To address the problem of long URLs and make them more manageable for users, a URL shortener service provides an effective solution. By condensing lengthy URLs into shorter, more concise forms, users can easily share and access links across various platforms and communication channels.

Shortening URLs

Implement a URL shortening algorithm to generate unique, shortcodes or aliases for long URLs. This algorithm should produce compact shortcodes that are unlikely to collide with existing codes in the system.

csharp
public async Task GenerateShortenUrlAsync(string destination, CancellationToken cancellation)
{
    var shortenCode = GenerateCode(destinationUrl);

    var link = new Link
    {
        CreatedOn = DateTime.UtcNow,
        DestinationUrl = destinationUrl,
        ShortenCode = shortenCode
    };

    await _dbContext.Links.AddAsync(link, cancellation);
    await _dbContext.SaveChangesAsync(cancellation);

    return $"{_appSettings.BaseUrl}/{shortenCode}";
}

Redirection Mechanism

Set up a redirection mechanism that maps incoming requests for shortened URLs to their corresponding long URLs. When a user accesses a shortened URL.

csharp
app.MapGet("/{short_code}", async (
    [FromRoute(Name = "short_code")] string ShortCode,
    ShortenUrlService shortenService,
    CancellationToken cancellationToken)
=> {
    var destinationUrl = await shortenService.GetDestinationUrlAsync(ShortCode, cancellationToken);

    return Results.Redirect(destinationUrl);
});

The service should redirect them seamlessly to the original destination URL without any noticeable delay.

Metrics

By systematically capturing and analyzing these metrics, marketing teams can gain insights into the effectiveness of their campaigns, identify potential issues, and optimize their strategies to enhance user engagement and achieve better outcomes.

…

License

This project is licensed under the MIT License: MIT License.

Stay Connected

Feel free to raise any questions or suggestions through GitHub issues.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#asp-net-corecsharpdotnetmongodb

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库