ASP. NET WEBAPI Open session

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.