问题描述
的有一个很大的问题在这里:的How对Web API添加到现有的ASP.NET MVC 4 Web应用程序项目?
不幸的是,这是不够的,解决我的问题。我已经试了两次,以确保我没有做错任何事。我右键点击控制器,并补充该项目的Web API 2控制器的操作,使用实体框架里,我选择我的模型类和数据库环境。一切都很好...但仍...每次我试图访问/ API /休息,我得到一个404错误(我的控制器是RestController的名称)。
Unfortunately, it wasn't enough to solve my problem. I've tried twice to be sure I haven't done anything wrong. I right clicked on "Controllers" and added the item "Web API 2 Controller with actions, using Entity Framework" where I selected my model class and db context. Everything went fine... but still... everytime I've tried to access /api/Rest I was getting a 404 error (The name of my Controller is RestController).
推荐答案
它的工作!我不想相信,但你猜怎么着,这个问题与在Global.asax路由为了与
It's working!!! I didn't want to believe, but guess what, the problem was related with the Global.asax routing order.
尽管它不与工作:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
GlobalConfiguration.Configure(WebApiConfig.Register); //I AM THE 4th
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
它适用于:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register); //I AM THE 2nd
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
疯了,我知道了。
Crazy, I know.
这篇关于添加Web API到现有的MVC Web应用程序后,404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!