asp.net mvc 应用程序的不同域和 url 缩短器

Different domain and url shortener for asp.net mvc app

我想实现一个简单的 URL 缩短器功能,例如 Bitly。

我的控制器名称:WebController

我的操作名称:重定向

顾名思义,该操作会将用户从短 URL 重定向到完整 URL。

要调用此操作,我需要:https://myappdomain.com/web/redirect?id=3422

但我希望能够使用不同的(更短的)域以更短的方式调用此功能,而无需调用操作名称:https://shorterdomain.com/3422

你能指导我怎么做吗?我什至不知道要搜索什么:(

添加到更短的路由 URL,以便 MVC 知道哪个控制器和操作将处理请求。像这样:

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(name: "redirection",
                pattern: "{id:int}",
                defaults: new { controller = "web", action = "redirect" });

    ... your existing routes
});