问题(追溯)添加Web API来的ASP.NET MVC项目 [英] Problems (retroactively) adding Web API to asp.net MVC project

查看:112
本文介绍了问题(追溯)添加Web API来的ASP.NET MVC项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要带我的第一个步骤,asp.net的MVC在Visual Studio 2013和我碰到一个奇怪的问题。

I'm taking my first steps with asp.net mvc in Visual Studio 2013 and I've run into a weird problem.

我开始我的项目为MVC和没有检查的Web API复选框以包括核心引用。但是现在我要使用Web API功能。我创建了一个新的somethingController控制器,选择的API控制器(空)和Visual Studio做了它的魔力,创造一个路由文件等。

I started my Project as MVC and did NOT check the "Web API" box to include the core references. However now I want to use the Web API functionality. I created a new "somethingController" controller, selected API controller (empty) and Visual Studio did it's magic, creating a routing file, etc.

但尝试访问URL / API /事/我木屐404我相信路由不工作或有我有没有想过一些其他的问题的时候又...

However when trying to access the URL /api/something/ I geta 404. I believe the routing doesn't work or there is some other problem I haven'T thought about yet...

如果我创建一个新的项目和checkt网络API框它工作得很好。但是,如果你有一个较大的项目,并希望添加的Web API功能,必须有一种简单的方法,以可靠的它添加到项目中,对吧?

It works just fine if I create a new Project and checkt the "Web API" box. But if you have a larger project and want to add Web API functionality there must be an easy way to reliable add it to the project, right?

有谁请解释

一)问题所在(路由?缺少引用?别的东西吗?)

a) Where the problem lies (routing? Missing references? something else?)

B)怎么能够可靠地在Web API的东西添加到没有启动的复选框选中的项目。

b) How can one reliably add the Web API stuff to a project that wasn't started with the checkbox checked.

非常感谢你。

推荐答案

好吧,看来我懂了工作。当您添加的第一个API控制器不具有网络API检查一个项目,一个自述文件有一些额外的信息弹出:

Ok, seems I got it working. When you add your first API controller to a project that does not have the Web API checked, a readme file pops up with some additional information:

我尝试添加

WebApiConfig.Register(GlobalConfiguration.Configuration);

要在Global.asax并没有奏效。自述呈现出以下code

to the global.asax and it did not work. the readme show the following code

GlobalConfiguration.Configure(WebApiConfig.Register);

这不工作,但它似乎(对我来说)这两个行做同样的事情??

that DOES work, although it seems (to me) that both lines do exactly the same thing??

这篇关于问题(追溯)添加Web API来的ASP.NET MVC项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆