MVC 5项目和Web API项目的区别 [英] Difference between MVC 5 Project and Web Api Project

查看:146
本文介绍了MVC 5项目和Web API项目的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的 Asp.net MVC和网页API 。我想获得的基本知识。正如,我们在VS 2013的项目模板命名为 MVC 网​​页API 这两个在一起

I am new to Asp.net MVC and Web Api.I am trying to get the basics. As, we have project templates in VS 2013 named as MVC, Web Api and Both of them together.

我已经通过了教程学习,我们可以通过单独使用MVC以及与网页API模板进行API。
因此,有人可以解释它们之间的差异的基础上的建筑明智和聪明的使用

I have gone through the tutorials and learn that we can make an Api by using MVC alone as well as with Web Api Template. So, can somebody explain the differences between these, based on architecture wise and usage wise.

推荐答案

基本上,一个的Web API 控制器是一个 MVC 控制器,它使用 HttpMessageResponse 为基本类型的反应,而不是 ActionResponse 。它们在大多数其它方面是相同的。项目类型之间的主要区别是, MVC应用程序项目类型添加了特定于Web之类的东西默认 CSS 的JavaScript 文件和所需要的网站等资源,这是不需要的API。

Basically, a Web API controller is an MVC controller, which uses HttpMessageResponse as the base type of its response, instead of ActionResponse. They are the same in most other respects. The main difference between the project types is that the MVC Application project type adds web specific things like default CSS, JavaScript files and other resources needed for a web site, which are not needed for an API.

MVC用于创建网站。在这种情况下控制器通常返回查看(即HTML响应)浏览器的请求。另一方面网络的API通常是由于由其他应用程序使用。如果你想允许其他应用程序访问数据/功能,可以创建一个Web API,以促成该进入。例如,Facebook有一个API,以便让应用程序开发人员访问有关使用App用户的信息。网络API不必须是用于公共消费。您还可以创建一个API来支持自己的应用程序。例如,我们创建了一个Web API来支持我们的MVC网站的AJAX功能。

MVC is used for creating web sites. In this case Controllers usually return a View (i.e. HTML response) to browser requests. Web APIs on the other hand are usually made to be consumed by other applications. If you want to allow other applications to access your data / functionality, you can create a Web API to facilitate this access. For example, Facebook has an API in order to allow App developers to access information about users using the App. Web APIs don't have to be for public consumption. You can also create an API to support your own applications. For example, we created a Web API to support the AJAX functionality of our MVC web site.

微软改变了他们的present不同模板的方式。现在,而不是使用不同的模板为不同的项目类型,它们鼓励开发人员需要在同一项目中混合使用ASP.NET技术。微软称这种 vNext

Microsoft changed the way they present the different templates. Now instead of using different templates for different project types, they encourage developers to mix ASP.NET technologies inside the same project as needed. Microsoft calls this vNext.

更新:看来,对于ASP.NET 5(目前在RC)的Web API将被集成到MVC 6项目类型和 ApiController 类将到控制器类合并。只是为了给一个单挑任何人刚才在寻找这一点。

UPDATE: It seems that for ASP.NET 5 (currently in RC) Web API will be integrated in to the MVC 6 project type and the ApiController class will be consolidated in to the Controller class. Just to give a heads-up to anyone just now looking in to this.

这篇关于MVC 5项目和Web API项目的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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