I would like to implement a simple URL shortener feature like Bitly.
My Controller name: WebController
My Action name: Redirect
As the name suggests the action redirects the user from the short URL to the full URL.
To call this action I need: https://myappdomain.com/web/redirect?id=3422
But I would like to be able to call this feature in a much shorter way with a different (shorter) domain and without the need to call the action name: https://shorterdomain.com/3422
Can you guide me how can I do this? I am a bit lost even for what to search for:(
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Add a route to the shorter URL so MVC knows what controller and action will handle the request. Something like this:
app.UseEndpoints(endpoints => { endpoints.MapControllerRoute(name: "redirection", pattern: "{id:int}", defaults: new { controller = "web", action = "redirect" }); ... your existing routes });
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0