0

I use OWIN to selfhost (I'm not using IIS) my web api and I was reading a lot about web applications based on asp.net web api and angularJS. In most examples there where a default route of the api like

HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_baseAddress);
config.Routes.MapHttpRoute(
  name: "DefaultApi",
  routeTemplate: "api/{controller}/{id}",
  defaults: new { id = RouteParameter.Optional }
);

But I don't understand where the route to the index.html file of the angularJS frontend happens? I know how to get data when I'm calling an api request like api/person/5. But which part of the code is responsible to route any unspecified api request to the main page of angularJS?

CPA
  • 2,923
  • 4
  • 30
  • 52

1 Answers1

0

Using WebAPI and a default route to Index.html is not a good idea. Because the calling would be yourapp.com/api/xxxx

Instead since you are using IIS (I assume you arent using OWIN to selfhost).In IIS you can and should set a default page.

This way your url will just look ile yourapp.com regardless of it being index.html, jack.html, or test.html

To answer your question But which part of the code is responsible to route any unspecified api request to the main page of angularJS?

app.config(function ($routeProvider) {

    $routeProvider.otherwise({ redirectTo: "/Main" });
});

use $routeprovider.otherwise to do the redirct. If you send an non-identifiable route to angular the otherwise config value will redirect you to your main in this instance.

This MSDN page will walk you through setting up a default page in iis

gh9
  • 10,169
  • 10
  • 63
  • 96
  • I use OWIN to selfhost. I will edit my question to make that clear. Sorry. Where would I set the default page when I'm using IIS? Thats why I can't find any route to index.html in these examples. Anyway, how can I do that with OWIN? – CPA Jan 13 '16 at 21:41
  • When I ment self hosting with OWIN, i was referring to not using IIS and using apache or something. – gh9 Jan 13 '16 at 21:43
  • I'm not using IIS. I'm completely decoupled from IIS. – CPA Jan 13 '16 at 21:51
  • 1
    @cpa http://stackoverflow.com/questions/25478222/how-to-set-default-static-web-page-for-katana-owin-self-hosted-app I would try this then. – gh9 Jan 13 '16 at 22:02