private static IMailboxContext AcquireUserContext(HttpContext httpContext, AuthZClientInfo effectiveCaller, UserContextKey userContextKey, UserContextCookie userContextCookie) { IMailboxContext mailboxContext = null; UserContextStatistics userContextStatistics = null; try { if (userContextKey != null) { mailboxContext = UserContextManager.GetMailboxContextFromCache(userContextKey); if (mailboxContext == null || mailboxContext.State == UserContextState.Abandoned) { UserContextManager.CreateUserContext(httpContext, userContextKey, effectiveCaller, out mailboxContext, out userContextStatistics); } } else { UserContextManager.CreateUserContext(httpContext, null, effectiveCaller, out mailboxContext, out userContextStatistics); string cookieId = null; if (mailboxContext != null) { userContextCookie = UserContextCookie.CreateFromKey(cookieId, mailboxContext.Key, httpContext.Request.IsSecureConnection); httpContext.Response.Cookies.Set(userContextCookie.HttpCookie); userContextStatistics.CookieCreated = true; } } } finally { if (userContextStatistics != null) { SignInLogEvent logEvent = new SignInLogEvent(mailboxContext, (userContextCookie != null) ? userContextCookie.CookieValue : string.Empty, userContextStatistics, httpContext.Request.Url); OwaServerLogger.AppendToLog(logEvent); } } return(mailboxContext); }