我想在Asp.Net MVC4中實現一個簡單的Breeze控制器,但似乎無法訪問它。它可能與.Net的標準Web.Api相沖突嗎?嘗試在asp.net中實現Breeze控制器mvc
如果我的網址是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 ... –
謝謝。不過,我仍然遇到同樣的錯誤。 WebApi可能並排存在衝突嗎? –
完全沒有。你的路線設置爲微風/ {控制器}/{動作},但你只能打電話給微風/ {控制器}。添加動作... –