First, the session reply support is not enabled by default in the WEBAPI project. You need to specify the types that members need to support in the Init () method in global
Public classwebapiapplication:system.web.httpapplication{/// <summary> ///website Launch/// </summary> protected voidApplication_Start () {/** Note that you must first enable cross-domain, and then enable the enrollment route*/GlobalConfiguration.Configuration.EnableCors (); Globalconfiguration.configure (Webapiconfig.register); } Public Override voidInit () { This. Postauthenticaterequest + = (sender, e) = ={ HttpContext.Current.SetSessionStateBehavior (System.Web.SessionState.SessionStateBehavior.Re quired); }; Base. Init (); }
In the default caseis not turned on. The Sessionstatebehavior has four values: default ASP is used. NET logic to determine the session state behavior of the request. The default logic is to look for the presence of a tagged session state interface in IHttpHandler.
Disabled Session state is not enabled to process requests. This setting overrides any session behavior that has been determined by the handler that inspected the request.
ReadOnly enables read-only session state for requests. This means that the session state cannot be updated. This setting overrides any session state behavior that has been determined by the handler that inspected the request.
The Required enables full read-write session state behavior for the request. This setting overrides any session behavior that has been determined by the handler that inspected the request.
MORE: ASP. NET WEBAPI Configuration Interface return data type to JSON format ASP. NET WebApi project and Dependency collation ASP. NET WEBAPI Post request collation (one)
ASP. NET WEBAPI Open session