using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Optimization; using System.Web.Routing; using System.Web.SessionState; namespace SocialMasterDataPortal { public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { this.InitializeAll(); //GlobalConfiguration.Configure(WebApiConfig.Register); WebApiConfig.Register(GlobalConfiguration.Configuration); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); GlobalConfiguration.Configuration.EnsureInitialized(); Heart.Initilize(); } //用于在webapi中支持session,重载这个方法就好了 public override void Init() { this.PostAuthenticateRequest += (sender, e) => HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required); base.Init(); } } }