So I'm trying to set up the routing for my project, I have a few different cases that need to be handled but I'm unable to make them work as intended.
case 1: / - Routes to the index of the angular app
Case 2: /{angular Route} - Routes to angulars routing but I'm guessing it first needs to be redirected to angular base page.
Case 3: /api/data/GetAllValues - Routes to the data api controller method and GetAllValues action
My base file for angular is stored at the root: /index.html but I have it so that when you go to this page angular will take you to /Index
This is the routing I have in WebApiConfig.Register which is invoked by the Global.asax
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
config.Routes.MapHttpRoute("AngularRedirect", "{.*}", "~/index.html");
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
And Angular routes
.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/Index',
{
templateUrl: 'Templates/Feed.html',
controller: 'feedController'
}
);
$routeProvider.when('/Lookup',
{
templateUrl: 'Templates/Lookup.html',
controller: 'lookupController'
}
);
$locationProvider.html5Mode(true);
$routeProvider.otherwise({ redirectTo: '/Index' });
I'm getting a few issues with this setup, neither case 1 or 2 work, both result in a message from asp.net with saying that it cannot match a url to the request
Edit: this is the error message when I try navigate to / (case 1)
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:49569/'.","MessageDetail":"No route providing a controller name was found to match request URI 'http://localhost:49569/'"}
Update:
I changed the asp.net default route to catch {.*} and now when I put in / it correctly redirects to angular but when I do /Index I am still gettign the error as below
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:49569/Index'.","MessageDetail":"No route providing a controller name was found to match request URI 'http://localhost:49569/Index'"}
/i get the message:{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:49569/'.","MessageDetail":"No route providing a controller name was found to match request URI 'http://localhost:49569/'"}