Question

I am trying to configure my MVC5/WebAPI2 REST Service to redirect to a separate Angular SPA located on a subfolder in the same site on IIS.

I have tried adding the Angular Index.html at the root of the web folder, but this does not work. I can access the file by name by going to

http://<hostname>/index.html

However, I obviously don't want the file name. I just want the default root (/) to load the angular app. The goal would be something like this-

http://<hostname> --> Angular app (angular router takes over for it's internal routes
http://<hostname>/api --> The REST service 
Was it helpful?

Solution 2

Building on what @Cybermaxs said, since I am going full SPA with no Razor views at all (except the Help Area), this is what worked for me- (basically cybermaxs, answer but I had to comment out the default mvc routes).

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.RouteExistingFiles = true;
        routes.MapRoute(
         name: "Home",
         url: "index.html",
         defaults: new { controller = "Home", action = "Index", page = UrlParameter.Optional }
        );

       /* routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional }
        );*/




        //point people to SPA
        routes.IgnoreRoute("apps");
        routes.IgnoreRoute("");

OTHER TIPS

You can add a new route in RouteConfig to map index.html to the default mvc entry point.

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.RouteExistingFiles = true;

        routes.MapRoute(
            name: "Home",
            url: "index.html",
            defaults: new { controller = "Home", action = "Index", page = UrlParameter.Optional }
        );
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top