【问题标题】:404 when access Breeze controller?访问 Breeze 控制器时出现 404?
【发布时间】:2013-11-19 22:51:00
【问题描述】:

我创建了一个 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}"
      );
    }
  }
}

【问题讨论】:

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


    【解决方案1】:

    您似乎错过了部分路线 -

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

    应该有效

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2017-07-14
        • 2011-11-29
        • 2015-11-04
        • 2014-12-07
        • 2016-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多