Hi,
Could someone please assist in my need to create a route that will handle all my short links without breaking the Signal R / Angular JS front end architecture?
What I need is e.g. host/shortlink1 should redirect to host/applicaiton#/listing/123
The /application#/object is be pre-defined or determined.
2 Answer(s)
-
0
Hi,
If users are going to use this short url directly (enter the page by writing short url to browser address bar and press enter), you need to handle it on MVC site. You can define a database table for mapping short url to long url and configure routes like this,
routes.MapRoute( "ShortUrls", "{name}", new {controller = "ShortUrl", action = "Index", name = UrlParameter.Optional} );
If this short url's are going to be used in angular app as inline urls, then you need to handle it on angular side This post has a sample plunker about it <a class="postlink" href="http://stackoverflow.com/questions/23830421/how-to-implement-path-aliases-in-ui-router/23853129#23853129">http://stackoverflow.com/questions/2383 ... 9#23853129</a>
This is the sample plunker <a class="postlink" href="http://plnkr.co/edit/mOZw4gHQh025FjFTPAKZ?p=preview">http://plnkr.co/edit/mOZw4gHQh025FjFTPAKZ?p=preview</a>
-
0
I did try that, and my route's doesn't work right. The only way I got around this was by adding a delimeter /sl/ in the url. However my requirement dictates that I cannot have that key delimeter. The only thing I know is that the application#/listing can be pre-defined in the route.
So the default route's that came with aspNetBoilerPlate are
routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new[] { "REP.Regional.Controllers" } );
When I add shortlink at the end and it will never trigger routes.MapRoute( name: "ShortLinks", url: "{name}", defaults: new { controller = "ShortLink", action = "Index", name = UrlParameter.Optional } );
If i add short link route in the middle of the route's it will loop indefinitely.
My ShortLinkController code is basic public ActionResult Index(string name) { if (!string.IsNullOrEmpty(name)) { ListResultOutput<ShortLinkListDto> shortLinks = AsyncHelper.RunSync(() => _shortlinkAppService.GetShortLinks(new GetShortLinkInput() { TenantFilter = 1, RegionFilter = 2004 })); ShortLinkListDto shortLink = shortLinks.Items.Where(e => e.Link.Trim().ToLower() == name.ToLower().Trim()).FirstOrDefault(); if (shortLink != null) { return Redirect(shortLink.FullLink); //this will redirect to /application#/listing/123 } } return Redirect("/"); }