我正在开发一个Angular应用程序,使用ASP.NET WebApi作为后端。
如果我从RouteConfig.cs中删除了catch-all路由,http://localhost:1653/api/feed就可以正常工作。
当我重新添加它时,它也会捕获api调用。
public class FeedController : ApiController
{
[HttpGet]
[Route("api/feed")]
public IEnumerable<FeedItem> Get()
{
var items = new List<FeedItem>();
items.Add(new FeedItem("News from the server!"));
return items;
}
}但删除后,Angular应用程序会在刷新时崩溃,因为需要使用覆盖所有视图的路由来显示所有视图。
routes.MapRoute(
name: "Default",
url: "{*anything}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);难道属性路由不应该处理这个问题吗?
发布于 2015-05-08 00:02:26
找到了:
protected void Application_Start()
{
Container = UnityConfig.InitializeUnity();
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
GlobalConfiguration.Configure(WebApiConfig.Register);
...如果RouteConfig在前面,它就不起作用了。好的,这就是:)
https://stackoverflow.com/questions/30101628
复制相似问题