404访问Breeze控制器时?

时间:2013-11-19 06:56:32

标签: asp.net asp.net-mvc breeze asp.net-mvc-5 hottowel

我创建了一个Asp.Net MVC 5项目,然后使用NuGet添加hottowl(包括Breeze)。 我有以下控制器。

[BreezeController]
public class BreezeController : ApiController
{
    readonly EFContextProvider<ApplicationDbContext> _contextProvider = new EFContextProvider<ApplicationDbContext>();

    [HttpGet]
    public string Metadata()
    {
        return _contextProvider.Metadata();
    }

    [HttpGet]
    public IQueryable<Event> Events()
    {
        return _contextProvider.Context.Events;
    }
}

以下代码存在于BreezeWebApiConfig.cs文件中。但是,在尝试访问http://localhost:49890/Breeze/Events时,我总是遇到404错误。我错过了什么吗?或者下面的微风路由不起作用?

using System.Web.Http;

[assembly: WebActivator.PreApplicationStartMethod(
    typeof(ST13a.App_Start.BreezeWebApiConfig), "RegisterBreezePreStart")]
namespace ST13a.App_Start {
  ///<summary>
  /// Inserts the Breeze Web API controller route at the front of all Web API routes
  ///</summary>
  ///<remarks>
  /// This class is discovered and run during startup; see
  /// http://blogs.msdn.com/b/davidebb/archive/2010/10/11/light-up-your-nupacks-with-startup-code-and-webactivator.aspx
  ///</remarks>
  public static class BreezeWebApiConfig {

    public static void RegisterBreezePreStart() {
      GlobalConfiguration.Configuration.Routes.MapHttpRoute(
          name: "BreezeApi",
          routeTemplate: "breeze/{controller}/{action}"
      );
    }
  }
}

2 个答案:

答案 0 :(得分:1)

看起来你错过了路线的一部分 -

http://localhost:49890/breeze/Breeze/Events

应该工作

如果您不想多余,可以更改前缀('breeze')或更改控制器名称('Breeze')

答案 1 :(得分:0)

你使用最新的微风吗?请参阅How will I use breeze with Entity Framework 6 with .net 4.0,其中说“您需要安装”Breeze Server - for Web API 2“(Breeze.Server.WebApi2)。”尝试更新您的hottowel包并尝试。

截至2013年11月19日,在4个hottowel软件包中,我只看到这个使用Breeze.Sever.WebApi2:HotTowel.Angular.Breeze。也许其他软件包需要更新以支持WebApi2。