[英]Structure of asp.net with web api and mvc controller
I have a question about the structure of asp.net website, especially back-end stuff 我对asp.net网站的结构有疑问,尤其是有关后端的内容
Currently, I have sql database, web api controller and mvc controller. 目前,我有sql数据库,web api控制器和mvc控制器。 I have been using web api for getting or posting data to database, and using mvc controller for directing webpage.
我一直在使用Web API来获取数据或将数据发布到数据库,并使用mvc控制器来定向网页。
What I want to do is as followings 我想做的如下
It is basically registration process 基本上是注册过程
Here is problem, since the web api will be used by other devices as well so I can't directly do some business logic for dealing with the duplication of email. 这是一个问题,因为Web api也将被其他设备使用,所以我不能直接做一些业务逻辑来处理电子邮件的重复。 So I just want to let somehow the MVC controller know the error and do some business logic.
因此,我只想让MVC控制器知道该错误并执行一些业务逻辑。
How can I do that?, Is it fine to return some status code like 101, 201 to MVC controller? 我该怎么办?,向MVC控制器返回一些状态代码(如101、201)可以吗? then How can I do that??
那我该怎么办呢?
Thanks guys 多谢你们
Use standard HttpResponse with a code from public enum HttpStatusCode Under the link you'll find the list of all codes and some examples how to use and consume them; 将标准HttpResponse与来自公共枚举HttpStatusCode的代码一起使用。在此链接下,您将找到所有代码的列表以及一些使用和使用它们的示例。
for example, in your API controller may return: 例如,在您的API控制器中,可能会返回:
return new HttpResponseMessage(HttpStatusCode.NotAcceptable);
and then on the consumer side you'll have to handle that error. 然后在消费者方面,您必须处理该错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.