ASP. NET5 Web API Controller Class learning
The Web API Controller Class is a template type used to add new items to ASP. NETWeb Application projects in VS2015. This template type generates a REST-style interface Class,
Why not choose MVCController Class?
Because we don't want it to involve a View, we don't need a View
ASP. NET Web API Model-ModelBinder,ASP. NET Web API Model-ModelBinder Preface
This article will introduce you to ASP. NET Web API ModelBinder binding principles and some object models involved, as well as simple Model binding exam
How do I view a query string? → Enter the URL that contains the query string, for example: http://localhost:54176/api/ProductCategories?name=darrenage=25→ Click the params, the query string is stored as a set of key-value teams→ Select key-value pairs, right-select "encodeURIComponent" to encrypt keys or valuesHow to use body? →form-data option, enter form data→x-www-form-urlencoded options, enter form data
are accessed through the static attribute GlobalConfiguration. Configuration. The Web API also defines several RouteCollection extension methods, called MapHttpRoute, to define the configuration of Web APIs. See the following example:
HttpConfiguration config = GlobalConfiguration. Configuration;Config. Routes. MapHtt
Reference page:Http://www.yuanjiaocheng.net/webapi/test-webapi.htmlHttp://www.yuanjiaocheng.net/webapi/web-api-controller.htmlHttp://www.yuanjiaocheng.net/webapi/config-webapi.htmlHttp://www.yuanjiaocheng.net/webapi/web-api-route.htmlHttp://www.yuanjiaocheng.net/webapi/parameter-binding.htmlThe ASP. NET
Asp. Net Web API (IV), asp. netwebapiHttpResponseException ----- HTTP Response exception
What happens if the Web API controller throws an uncaptured exception? By default, most exceptions are converted to an HTTP response with an internal server error code 500.
The HTTPResponseException type is a special type. This exc
is what
Web API, Network application interface. It contains a wide range of functions, network applications through the API interface, can achieve storage services, messaging services, computing services, the ability to use these capabilities to develop a powerful Web application. In simple terms, it's an interface, f
Document directory
Use HTTP Message Handlers for authentication
Set Principal
Use the [Authorize] attribute
Custom Authorization Filters
Authorize in Controller Action
English address: http://www.asp.net/web-api/overview/security/authentication-and-authorization-in-aspnet-web-api
This article is what the autho
logging after an exception, which runs through the entire Web API's lifecycle, and in the Web API framework, any one of the request cycles is not captured/ The exception that is handled will first go into the Exception Log record pipeline, which can register multiple Iexceptionlogger instances for different exception handling in the
Amazon historcal Pricing Services, and the latest Yahoo! Answer's API login. What these services have in common is that they all provideSimple APIs to access massive data may lead to unpredictable cross-application of isolated information.Search Service: because of its basic and dominant position in the web field, search service forms a key part of the new web i
ObjectiveWhen designing external Web APIs, there may be cases where the old and new versions of APIs coexist, such as open Web APIs to vendors, but when the same service is updated, it is not always possible for all vendors to update their systems at the same time, but if the service is changed directly into a new one, These vendors may not be able to connect with your service until they are in the new vers
development of this single-page program
Project ArchitectureAfter stripping a picture, my picture has to be drawn with its coordination, no my handwriting style looks good, has the wood?
Using knockout as the front-end MVVM framework
To load a remote template with Requirejs
Use director as the front-end route.
Model data is directly interacting with the Web API, including authenti
:37.9116538z".indenting--IndentTo write the indented XML, set the Indent property to true:Set the XML serializer for each type (Per-type)You can set different XML serializers for different CLR types. For example, you might have a special data object that needs to be XmlSerializerfor backwards compatibility. You can use XmlSerializerfor this object and continue to use DataContractSerializerfor other types.To set up an XML serializer for a special type,
); return new HttpStatusCodeResult(204); // 201 No Content } }}Similarly, I created the Controllers folder to store the controller.In subsequent chapters, we will further elaborate on the Controller code. The following are some basic functions implemented by the controller:For example, the following is an HTTP request for obtaining the ToDo project:GET http://localhost:5000/api/todo HTT
define an ASP. NET WEB API controller to support get requests to the product entity set:namespacePattern.DI.MVC.Controllers{ Public classProductcontroller:apicontroller{ Private ReadOnlyProductrepository productrepository=NewProductrepository (); PublicIenumerable{ returnProductrepository.getall ();} PublicProduct Get (intId{ returnProductrepository.getbyid
English Original address: Http://www.asp.net/web-api/overview/security/authentication-and-authorization-in-aspnet-web-apiThis article is the content that the author understands and translates.This article includes two parts: Authentication and authorization.
Authentication is used to determine the identity of a user. For
.3. xml or JSON?
The web API is automatically selected based on the HTTP header of the Request Message:
Accept: Application/JSONContent-Type: Application/JSON
Content-Type indicates the data type in the Request body, whether it is JSON or XML, or an image or something. Accept indicates the expected data type of the request. The above request indicates that the data in the Request Message Body is JSON, and t
background:V. Pass a POST request for a parameter:First of all, we need to remind you that after we have modified the background code, if we do not rebuild the project, then the request will be error: "The request matching HTTP resource not found":So, as long as we modify the background code, we must regenerate it:However, when we re-build the project, send the request again, see the 404 error again, check the code again, and don't find out where the problem is. In fact, the ASP. NET
produce JSON.Use StringBuilder to generate JSON and return stringcontent at the end as the content that responds in Webapi.var response = Request.createresponse (Httpstatuscode.ok); response. Content = New Stringcontent (Jsonresult, Encoding.UTF8, "Application/json"); return response; 3) Use other protocol formats as much as possible (protocol buffer, message pack)If you can use other message formats in your project, such as Protocol buffers or messagepack instead of using JSON as a protocol
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.