Guido Caffa
Guido Caffa

Reputation: 1251

C# Web Api + AngularJS Route in separeted projects don't work

I have a Solution with two projects. One is the frontend, made with AngularJS, the backend is made with c# web api. When I use the debugger with only backend the api url's work fine, but when I debug the two projects at the same time web api doesn't work. I use Angular Route for my app routing, could this be the problem?

WebApiConfig.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace ServiApi
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Configuración y servicios de API web

            // Rutas de API web
            config.MapHttpAttributeRoutes();

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

app.js

var app = angular.module('app', ['ngRoute']);


app.config(['$routeProvider',

    function ($routeProvider) {
    $routeProvider
        .when('/home', {
            templateUrl: 'views/home.html',
        })
        .when('/news', {
            templateUrl: 'views/news.html',
        })
        .otherwise({ redirectTo: '/home' });
}]);

Upvotes: 0

Views: 41

Answers (0)

Related Questions