예제 #1
0
        protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);

            if (User.Identity.IsAuthenticated)
            {
                var request = controllerContext.Request;

                // get connection name from claims
                ClaimsPrincipal principal = request.GetRequestContext().Principal as ClaimsPrincipal;
                var             site      = principal.Claims.Where(c => c.Type == "site").Single().Value;

                // create db connection
                cp = new ConnectionProvider(site);
                ApiService.dbConnection = cp.CreateDbConnection();
                ApiService.Site         = site;

                // set global data
                ApiService.UserId     = User.Identity.Name;
                ApiService.HostName   = request.Headers.Host;
                ApiService.ClientDate = request.Headers.Date.HasValue ? request.Headers.Date.Value.LocalDateTime : DateTime.Now;     // set client date
            }
        }