ASP.NET Web API比ASP.NET MVC有什么好处

时间:2021-06-18 01:50:03

I frequency experience that Web API has some limitations and some disadvantages that not exists in "ASP.NET MVC".

我频繁地体验到Web API有一些限制和“ASP.NET MVC”中不存在的一些缺点。

For instance, ASP.NET Web API doesn't support [OutputCache] attribute "Out of the box" so i had to install NuGet add-on for supporting it.

例如,ASP.NET Web API不支持[OutputCache]属性“开箱即用”,因此我必须安装NuGet插件才能支持它。

My question is, why should i choose to work with ASP.NET Web API if i can choose ASP.NET MVC that as far as i know can do whatever WEB API can do and even more?

我的问题是,如果我可以选择ASP.NET MVC,为什么我应该选择使用ASP.NET Web API,据我所知,它可以做任何WEB API可以做的甚至更多?

3 个解决方案

#1


9  

ASP.NET MVC is an MVC framework for building web aplications. ASP.NET Web API is a framework for building RESTful services. That's the main difference of the two frameworks. They have been built for different purposes and they should be used for the purpose they have been built.

ASP.NET MVC是用于构建Web应用程序的MVC框架。 ASP.NET Web API是用于构建RESTful服务的框架。这是两个框架的主要区别。它们是为不同目的而建造的,它们应该用于它们的建造目的。

A comparison between ASP.NET Web API and WCF would have been more reasonable, because both are used for the implementaion of SOA (Service Oriented Architecture) solutions. On the other hand, I don't think that we should relate ASP.NET Web API with ASP.NET MVC.

ASP.NET Web API和WCF之间的比较会更合理,因为它们都用于实现SOA(面向服务的体系结构)解决方案。另一方面,我认为我们不应该将ASP.NET Web API与ASP.NET MVC联系起来。

#2


2  

ASP.NET MVC is optimized to return content to a web browser over HTTP and is based on the ASP.NET runtime (system.web) that has been around for > 10 years.

ASP.NET MVC经过优化,可以通过HTTP将内容返回到Web浏览器,并且基于已经存在超过10年的ASP.NET运行时(system.web)。

ASP.NET Web API is a HTTP application framework that does not care what client you are serving. It is built on a new Http stack that can be used for both the client and server side.

ASP.NET Web API是一个HTTP应用程序框架,它不关心您所服务的客户端。它建立在一个新的Http堆栈上,可以用于客户端和服务器端。

Both frameworks can produce RESTful applications, neither are particularly optimized for it.

这两个框架都可以生成RESTful应用程序,也没有特别针对它进行优化。

#3


1  

MVC is a framework for develop web application but Web api is for develop REST service. we can compair WebAPI with Wcf because both are for develop for services.

MVC是用于开发Web应用程序的框架,但Web api用于开发REST服务。我们可以用Wcf来兼顾WebAPI,因为它们都是用于服务的开发。

when we use WebApi then we no need to add attribute on method like Get,Put etc but we have to make method name start with GetEmployee,PutEmployee,PostEmployee etc..

当我们使用WebApi时,我们不需要在Get,Put等方法上添加属性,但是我们必须使用GetEmployee,PutEmployee,PostEmployee等来创建方法名称。

authentication is more simple we can authenticate user at entry point of the service,no need to authenticate at every method or controller. only we have to add "Authenticate" attribute on method or controller as per requirement.

身份验证更简单我们可以在服务的入口点验证用户,无需在每个方法或控制器上进行身份验证。只有我们必须根据需要在方法或控制器上添加“Authenticate”属性。

#1


9  

ASP.NET MVC is an MVC framework for building web aplications. ASP.NET Web API is a framework for building RESTful services. That's the main difference of the two frameworks. They have been built for different purposes and they should be used for the purpose they have been built.

ASP.NET MVC是用于构建Web应用程序的MVC框架。 ASP.NET Web API是用于构建RESTful服务的框架。这是两个框架的主要区别。它们是为不同目的而建造的,它们应该用于它们的建造目的。

A comparison between ASP.NET Web API and WCF would have been more reasonable, because both are used for the implementaion of SOA (Service Oriented Architecture) solutions. On the other hand, I don't think that we should relate ASP.NET Web API with ASP.NET MVC.

ASP.NET Web API和WCF之间的比较会更合理,因为它们都用于实现SOA(面向服务的体系结构)解决方案。另一方面,我认为我们不应该将ASP.NET Web API与ASP.NET MVC联系起来。

#2


2  

ASP.NET MVC is optimized to return content to a web browser over HTTP and is based on the ASP.NET runtime (system.web) that has been around for > 10 years.

ASP.NET MVC经过优化,可以通过HTTP将内容返回到Web浏览器,并且基于已经存在超过10年的ASP.NET运行时(system.web)。

ASP.NET Web API is a HTTP application framework that does not care what client you are serving. It is built on a new Http stack that can be used for both the client and server side.

ASP.NET Web API是一个HTTP应用程序框架,它不关心您所服务的客户端。它建立在一个新的Http堆栈上,可以用于客户端和服务器端。

Both frameworks can produce RESTful applications, neither are particularly optimized for it.

这两个框架都可以生成RESTful应用程序,也没有特别针对它进行优化。

#3


1  

MVC is a framework for develop web application but Web api is for develop REST service. we can compair WebAPI with Wcf because both are for develop for services.

MVC是用于开发Web应用程序的框架,但Web api用于开发REST服务。我们可以用Wcf来兼顾WebAPI,因为它们都是用于服务的开发。

when we use WebApi then we no need to add attribute on method like Get,Put etc but we have to make method name start with GetEmployee,PutEmployee,PostEmployee etc..

当我们使用WebApi时,我们不需要在Get,Put等方法上添加属性,但是我们必须使用GetEmployee,PutEmployee,PostEmployee等来创建方法名称。

authentication is more simple we can authenticate user at entry point of the service,no need to authenticate at every method or controller. only we have to add "Authenticate" attribute on method or controller as per requirement.

身份验证更简单我们可以在服务的入口点验证用户,无需在每个方法或控制器上进行身份验证。只有我们必须根据需要在方法或控制器上添加“Authenticate”属性。