Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Friendly URL #1448


User avatar
0
aaronphoenix created

Hi,

I need to create a friendly URL where it will redirect to /application#/listings/123.

From what I know I need to add a route in route.config. However when I do that, the signal R / Angular is no longer kicking in.

Basically I want host/friendlyURL (without any specific object/action it should go to my ShortLinkController, and from there I would redirect to the appropriate location). My problem lies as it breaks the Angular framework when I put this as the default route specific key / identifier.


2 Answer(s)
  • User Avatar
    0
    phoenix created

    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) { return Redirect("/application#/listing/123"); }

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you try to change your route config like this.

    routes.MapRoute(
        name: "Default",
        url: "",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        namespaces: new[] { "**********.Web.Controllers" }
    );
    
    routes.MapRoute(
        name: "URL",
        url: "{name}",
        defaults: new { controller = "ShortLink", action = "Index", name = UrlParameter.Optional },
        namespaces: new[] { "**********.Web.Controllers" }
    );
    
    routes.MapRoute(
        name: "Basic",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", id = UrlParameter.Optional },
        namespaces: new[] { "**********.Web.Controllers" }
    );
    

    Then in your ShortLinkController controller, redirect like this,

    return Redirect("Application/Index#/users");
    

    I hope this helps.