【发布时间】:2014-07-01 17:37:17
【问题描述】:
我正在尝试在 Asp.Net MVC4 中实现一个简单的 Breeze 控制器,但似乎无法访问它。会不会和 .Net 的标准 Web.Api 冲突?
如果我的 url 是 http://localhost:49479/api/values,那么我会从 Web Api 获得良好的返回值。
但是,如果我的网址是 http://localhost:49479/breeze/Breeze,我会得到 "Http 404" error "Resource not found"。
如果我的网址是http://localhost:49479/breeze/Breeze/5,我会收到错误No HTTP resource was found that matches the request URI 'http://localhost:49479/breeze/Breeze/5'.
非常感谢您的建议。
这是我在 ..Controllers/BreezeController.cs 中的内容:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Breeze.ContextProvider;
using Breeze.WebApi2;
using Newtonsoft.Json;
namespace RageSys.Controllers
{
[BreezeController]
public class BreeezeController : ApiController
{
// GET api/values
public string Get(int id)
{
return "value";
}
public IEnumerable<string> GetMtm(int id)
{
return new string[] { "value1", "value2" };
}
}
}
在 BreezeWebApiConfig.cs 中:
using System.Web.Http;
[assembly: WebActivator.PreApplicationStartMethod(
typeof(RageSys.App_Start.BreezeWebApiConfig), "RegisterBreezePreStart")]
namespace RageSys.App_Start {
///<summary>
/// Inserts the Breeze Web API controller route at the front of all Web API routes
///</summary>
public static class BreezeWebApiConfig {
public static void RegisterBreezePreStart() {
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "BreezeApi",
routeTemplate: "breeze/{controller}/{action}"
);
}
}
}
【问题讨论】:
-
您的控制器名为 Breeeze 控制器,带有 3 个 e's...
-
谢谢。不过,我仍然遇到同样的错误。 WebApi 是否存在冲突?
-
一点也不。您的路线是为微风/{controller}/{action} 设置的,但您只调用微风/{controller}。添加操作...
-
@PWKad - 因此,如果我将其称为 localhost:49479/breeze/breeze/5,为什么我仍然会收到错误消息“未找到与请求 URI 匹配的 HTTP 资源。但是,当我调用 localhost:49479/api/values/5 时它确实有效.
-
把它改成微风/微风/GetMtm/1之类的东西
标签: asp.net-mvc-4 breeze