public bool TrySwitchOwaHostNameAndReturnPermanentRedirect(HttpContext context)
        {
            HttpRequest  request    = context.Request;
            Uri          uri        = request.GetRequestUrlEvenIfProxied();
            HttpResponse response   = context.Response;
            HttpCookie   httpCookie = request.Cookies.Get("HostSwitch");
            bool         flag       = httpCookie != null && httpCookie.Value == "1";
            string       host       = uri.Host;
            string       host2      = null;

            if (flag && request.RequestType == "GET" && this.IsDeprecatedHostName(host, out host2) && this.IsOwaStartPageRequest(uri) && !this.HasNonRedirectableQueryParams(request.QueryString.AllKeys))
            {
                bool flag2 = OfflineClientRequestUtilities.IsRequestForAppCachedVersion(context);
                bool flag3 = OfflineClientRequestUtilities.IsRequestFromMOWAClient(request, request.UserAgent);
                if (!flag2 && !flag3)
                {
                    uri = new UriBuilder(uri)
                    {
                        Host = host2
                    }.Uri;
                    this.RedirectPermanent(context, uri);
                    return(true);
                }
            }
            return(false);
        }
        private static bool RedirectBecauseClientForgotTrailingSlashOnRoot(HttpApplication httpApplication, HttpContext httpContext, Uri originalUri)
        {
            bool        result  = false;
            HttpRequest request = httpContext.Request;

            if (request.HttpMethod == "GET")
            {
                string absolutePath  = originalUri.AbsolutePath;
                string rootWithSlash = RequestDispatcher.GetRootWithSlash();
                string value         = rootWithSlash.TrimEnd(new char[]
                {
                    '/'
                });
                if (absolutePath.Equals(value, StringComparison.OrdinalIgnoreCase))
                {
                    if (string.IsNullOrEmpty(originalUri.Query) && OfflineClientRequestUtilities.IsRequestForAppCachedVersion(httpContext))
                    {
                        RequestDispatcher.SendJavascriptRedirectTo(httpApplication, httpContext.Response, rootWithSlash);
                        result = true;
                    }
                    else
                    {
                        RequestDispatcher.Send301RedirectTo(httpContext.Response, rootWithSlash + originalUri.Query);
                        result = true;
                    }
                }
            }
            return(result);
        }
示例#3
0
        public void ProcessRequest(HttpContext context)
        {
            string      userContextId           = Plt1WebHandler.GetUserContextId(context);
            bool        isMowa                  = OfflineClientRequestUtilities.IsRequestFromMOWAClient(context.Request, context.Request.UserAgent);
            HttpRequest request                 = context.Request;
            string      clientAddressWithoutPII = this.GetClientAddressWithoutPII(request);
            UserAgent   userAgent               = OwaUserAgentUtilities.CreateUserAgentWithLayoutOverride(context);
            string      userName                = string.Empty;
            string      cookieValueAndSetIfNull = ClientIdCookie.GetCookieValueAndSetIfNull(context);
            UserContext userContext             = UserContextManager.GetUserContext(context, false);

            if (userContext != null && userContext.LogonIdentity != null)
            {
                SmtpAddress primarySmtpAddress = userContext.LogonIdentity.PrimarySmtpAddress;
                userName = userContext.LogonIdentity.PrimarySmtpAddress.ToString();
            }
            if (Plt1WebHandler.IsPlt1PerformanceRequest(request))
            {
                string text = "";
                if (context.Request.HttpMethod == "POST")
                {
                    using (StreamReader streamReader = new StreamReader(context.Request.InputStream))
                    {
                        text = streamReader.ReadToEnd();
                        context.Response.AppendToLog(text);
                    }
                }
                string clientVersion = context.Request.QueryString.Get("cver") ?? string.Empty;
                Uri    uri;
                string refererQueryString = request.TryParseUrlReferrer(out uri) ? uri.Query : "noRefUrl";
                Dictionary <string, string> dictionary  = new Dictionary <string, string>();
                Dictionary <string, string> dictionary2 = new Dictionary <string, string>();
                Plt1WebHandler.GetPlt1PerformanceEventData(userAgent, refererQueryString, request.QueryString, text, dictionary, dictionary2);
                Plt1WebHandler.AddClientLoadTimeDataPoint(dictionary, dictionary2, userContextId, clientAddressWithoutPII, clientVersion, isMowa, userName, userContext, cookieValueAndSetIfNull);
                if (dictionary2.Count > 0 && dictionary.ContainsKey("msg") && dictionary["msg"].Contains("success"))
                {
                    Plt1WebHandler.AddCalculatedClientLoadTimeDataPoint(dictionary, dictionary2, userContextId, clientAddressWithoutPII, clientVersion, isMowa, userName, cookieValueAndSetIfNull);
                }
                if (userContext != null && userContext.FeaturesManager != null && userContext.FeaturesManager.ServerSettings.OwaServerLogonActivityLogging.Enabled)
                {
                    this.AddtoActivityLog(userContext, dictionary, userName, clientAddressWithoutPII, userAgent.RawString);
                }
            }
            else
            {
                string         clientVersion2  = context.Request.QueryString.Get("v") ?? string.Empty;
                ClientLogEvent plt1AccessEvent = Plt1WebHandler.GetPlt1AccessEvent(userContextId, request.UserAgent, clientAddressWithoutPII, clientVersion2, isMowa, cookieValueAndSetIfNull);
                OwaClientLogger.AppendToLog(plt1AccessEvent);
            }
            Plt1WebHandler.SetResponseHeaders(context.Response);
            Plt1WebHandler.WriteImage(context.Response);
        }
示例#4
0
        protected virtual bool GetIsClientAppCacheEnabled(HttpContext context)
        {
            bool flag = false;
            NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(context.Request.Url.Query);

            foreach (string text in nameValueCollection.AllKeys)
            {
                string text2;
                if (text == null || !DefaultPageBase.ParamsInAppCache.TryGetValue(text.ToLowerInvariant(), out text2) || (text2 != null && text2 != context.Request.Params[text]))
                {
                    flag = true;
                    break;
                }
            }
            return((!flag && OfflineClientRequestUtilities.IsRequestForAppCachedVersion(context)) || DefaultPageBase.IsPalEnabled(context, this.UserAgent.RawString));
        }
示例#5
0
        private void OnBeginRequestInternal(HttpApplication httpApplication)
        {
            HttpContext context = httpApplication.Context;
            HttpRequest request = context.Request;

            if (context.Request.IsSecureConnection)
            {
                string       text = request.Url.AbsolutePath ?? string.Empty;
                string       requestPathAndQuery = request.Url.PathAndQuery ?? string.Empty;
                string       text2    = request.Url.AbsoluteUri ?? string.Empty;
                HttpResponse response = context.Response;
                if (OwaJavascriptRedirectModule.gallatinSplashPageEnabled && OwaJavascriptRedirectModule.gallatinSplashPageRequiredForUrl.Equals(text2, StringComparison.OrdinalIgnoreCase))
                {
                    context.Server.TransferRequest("/owa/auth/outlookcn.aspx");
                    return;
                }
                if (string.IsNullOrEmpty(text) || text == "/")
                {
                    if (OfflineClientRequestUtilities.IsRequestForAppCachedVersion(context))
                    {
                        string arg = Uri.EscapeUriString(Uri.UnescapeDataString("/owa/" + context.Request.Url.Query));
                        response.StatusCode  = 200;
                        response.ContentType = "text/html";
                        response.Write(string.Format("<!DOCTYPE html><html><head><script type=\"text/javascript\">window.location.replace(\"{0}\" + window.location.hash);</script></head><body></body></html>", arg));
                        response.AppendToLog("OwaJavascriptRedirectUri=/owa/");
                        httpApplication.CompleteRequest();
                        return;
                    }
                    HttpRedirectCommon.RedirectRequestToNewUri(httpApplication, HttpRedirectCommon.HttpRedirectType.Permanent, new UriBuilder(text2)
                    {
                        Path = "/owa/"
                    }.Uri, "Owa301RedirectUri=");
                    return;
                }
                else
                {
                    string empty = string.Empty;
                    if (OwaJavascriptRedirectModule.TryGetOwa302PathAndQuery(text, requestPathAndQuery, out empty))
                    {
                        response.AppendToLog("Owa302RedirectUri=" + empty);
                        response.Redirect(empty);
                    }
                }
            }
        }
示例#6
0
 public static bool IsPalEnabled(HttpContext context, string userAgent)
 {
     return(OfflineClientRequestUtilities.IsRequestFromMOWAClient(context.Request, userAgent));
 }
        public virtual bool IsUserAgentExcludedFromHostNameSwitchFlight(HttpRequest request)
        {
            UserAgent userAgent = new UserAgent(request.UserAgent, false, request.Cookies);

            return(OfflineClientRequestUtilities.IsRequestFromMOWAClient(request, request.UserAgent) || userAgent.IsIos || userAgent.IsAndroid);
        }
示例#8
0
        private object InternalAfterReceiveRequest(ref Message request, RequestDetailsLogger logger)
        {
            try
            {
                Globals.UpdateErrorTracingConfiguration();
                IActivityScope             activityScope = OwaApplication.GetRequestDetailsLogger.ActivityScope;
                HttpRequestMessageProperty httpRequestMessageProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
                string value = httpRequestMessageProperty.Headers[OWADispatchOperationSelector.Action];
                activityScope.SetProperty(ExtensibleLoggerMetadata.EventId, value);
                string value2 = httpRequestMessageProperty.Headers["X-OWA-ClientBuildVersion"];
                if (!string.IsNullOrEmpty(value2))
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, value2);
                }
                else
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.ClientBuildVersion, "NA");
                }
                string value3 = httpRequestMessageProperty.Headers["X-EWS-TargetVersion"];
                if (!string.IsNullOrEmpty(value3))
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, value3);
                }
                else
                {
                    activityScope.SetProperty(OwaServerLogger.LoggerData.RequestVersion, "NA");
                }
                JsonMessageHeaderProcessor jsonMessageHeaderProcessor = new JsonMessageHeaderProcessor();
                string methodName = OWAMessageInspector.GetMethodName(request);
                bool   flag       = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName);
                bool   flag2      = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName);
                bool   flag3      = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName);
                if (flag || flag2 || flag3)
                {
                    using (MessageBuffer messageBuffer = request.CreateBufferedCopy(int.MaxValue))
                    {
                        Message request2 = messageBuffer.CreateMessage();
                        if (flag)
                        {
                            jsonMessageHeaderProcessor.ProcessMessageHeaders(request2);
                            jsonMessageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(request);
                        }
                        else if (flag2)
                        {
                            jsonMessageHeaderProcessor.ProcessMessageHeadersFromQueryString(request2);
                        }
                        else if (flag3)
                        {
                            jsonMessageHeaderProcessor.ProcessHttpHeaders(request, ExchangeVersion.Exchange2013);
                        }
                        request = messageBuffer.CreateMessage();
                    }
                }
                request.Properties["MessageHeaderProcessor"] = jsonMessageHeaderProcessor;
                request.Properties["ConnectionCostType"]     = 0;
                WebMethodEntry jsonWebMethodEntry;
                if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry))
                {
                    jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry;
                }
                request.Properties["WebMethodEntry"] = jsonWebMethodEntry;
                MessageHeaderProcessor messageHeaderProcessor = (MessageHeaderProcessor)request.Properties["MessageHeaderProcessor"];
                messageHeaderProcessor.MarkMessageHeaderAsUnderstoodIfExists(request, "RequestServerVersion", "http://schemas.microsoft.com/exchange/services/2006/types");
                RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitBegin);
                Message     requestRef  = request;
                CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(requestRef, messageHeaderProcessor, true, ""));
                RequestDetailsLogger.LogEvent(logger, OwaServerLogger.LoggerData.CallContextInitEnd);
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0);
                bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request));
                if (flag4 != null)
                {
                    callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0);
                }
                callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current);
                if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser))
                {
                    OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext);
                    OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext);
                    OWAMessageInspector.CheckClientVersion(callContext);
                    OWAMessageInspector.CheckMowaDisabled(callContext);
                    OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext);
                }
                OWAMessageInspector.MarkResponseNonCacheable(methodName);
                callContext.WorkloadType       = WorkloadType.Owa;
                callContext.UsingWcfDispatcher = true;
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 1);
                if (ExchangeVersion.Current == ExchangeVersion.Exchange2007)
                {
                    ExchangeVersion.Current = ExchangeVersion.Exchange2013;
                }
                if (OWAMessageInspector.ShouldCreateUserContext(callContext))
                {
                    UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext;
                    if (userContext != null)
                    {
                        callContext.OwaCulture = userContext.UserCulture;
                        if (userContext.FeaturesManager != null)
                        {
                            callContext.FeaturesManager = userContext.FeaturesManager;
                            if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled)
                            {
                                callContext.OwaUserContextKey = userContext.Key.ToString();
                            }
                        }
                    }
                }
            }
            catch (LocalizedException ex)
            {
                Microsoft.Exchange.Diagnostics.Components.Services.ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, string>((long)this.GetHashCode(), "[OWAMessageInspector::AfterReceiveRequest] Caught localized exception trying to create callcontext.  Class: {0}, Message: {1}", ex.GetType().FullName, ex.Message);
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex)));
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException");

                throw OwaFaultExceptionUtilities.CreateFault(ex);
            }
            return(null);
        }
        private static bool RedirectBecauseIE10RequiresReloadFromAppcache(HttpApplication httpApplication, HttpContext httpContext, Uri originalUri)
        {
            bool        result  = false;
            HttpRequest request = httpContext.Request;

            if (request.HttpMethod == "GET")
            {
                string absolutePath  = originalUri.AbsolutePath;
                string rootWithSlash = RequestDispatcher.GetRootWithSlash();
                if (absolutePath.Equals(rootWithSlash, StringComparison.OrdinalIgnoreCase) && RequestDispatcher.IsBrowserIE10(httpContext) && !OfflineClientRequestUtilities.IsRequestForAppCachedVersion(httpContext) && !DefaultPageBase.IsPalEnabled(httpContext))
                {
                    result = RequestDispatcher.ForceIE10ReloadToUseAppcacheIfNotAlreadyDone(httpApplication, httpContext);
                }
            }
            return(result);
        }
示例#10
0
        private static DispatchStepResult ValidateAndSetThreadCulture(RequestContext requestContext)
        {
            ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::ValidateAndSetThreadCulture] entry.");
            CultureInfo     cultureInfo     = null;
            EcpUserSettings ecpUserSettings = (EcpUserSettings)0U;
            UserContext     userContext     = requestContext.UserContext as UserContext;

            if (requestContext.UserContext != null && userContext == null)
            {
                throw new OwaInvalidOperationException(string.Format("Context was expected to be of type UserContext, but it is of type {0}", requestContext.UserContext.GetType()));
            }
            if (RequestDispatcherUtilities.TryReadUpdatedUserSettingsCookie(requestContext, out ecpUserSettings))
            {
                cultureInfo = RequestDispatcherUtilities.GetUserCultureFromEcpCookie(requestContext, ecpUserSettings);
                if (userContext != null)
                {
                    userContext.RefreshUserSettings(cultureInfo, ecpUserSettings);
                }
                RequestDispatcherUtilities.DeleteUserSettingsCookie(requestContext);
            }
            if (cultureInfo == null)
            {
                bool flag = requestContext.RequestType == OwaRequestType.SuiteServiceProxyPage;
                if (requestContext.LanguagePostUserCulture != null)
                {
                    cultureInfo = requestContext.LanguagePostUserCulture;
                }
                else if (userContext != null && !flag)
                {
                    cultureInfo = Culture.GetPreferredCultureInfo(userContext.ExchangePrincipal);
                    if (cultureInfo == null && userContext.IsExplicitLogon)
                    {
                        cultureInfo             = ClientCultures.GetPreferredCultureInfo(userContext.LogonIdentity.GetOWAMiniRecipient().Languages);
                        userContext.UserCulture = cultureInfo;
                    }
                    if (cultureInfo == null)
                    {
                        if (string.IsNullOrEmpty(requestContext.DestinationUrlQueryString))
                        {
                            requestContext.DestinationUrlQueryString = requestContext.HttpContext.Request.QueryString.ToString();
                        }
                        bool        flag2 = string.IsNullOrEmpty(requestContext.HttpContext.Request.Headers["X-SuiteServiceProxyOrigin"]);
                        CultureInfo culture;
                        string      timeZoneKeyName;
                        if (OfflineClientRequestUtilities.IsRequestFromMOWAClient(requestContext.HttpContext.Request, requestContext.HttpContext.Request.UserAgent) && RequestDispatcherUtilities.TryReadMowaGlobalizationSettings(requestContext, out culture, out timeZoneKeyName))
                        {
                            return(RequestDispatcher.HandleLanguagePost(requestContext, culture, timeZoneKeyName, false, requestContext.DestinationUrl));
                        }
                        if (flag2)
                        {
                            requestContext.DestinationUrl = RequestDispatcherUtilities.GetDestinationForRedirectToLanguagePage(requestContext);
                            requestContext.HttpContext.Response.AppendHeader("X-OWA-Version", Globals.ApplicationVersion);
                            requestContext.HttpContext.Response.AppendToLog("&redir=lang");
                            return(DispatchStepResult.RedirectToUrl);
                        }
                        requestContext.HttpContext.Response.Headers["X-OWA-Error"] = "OwaInvalidUserLanguageException";
                        requestContext.HttpStatusCode = HttpStatusCode.NoContent;
                        return(DispatchStepResult.EndResponse);
                    }
                    else if (userContext.IsUserCultureExplicitlySet)
                    {
                        cultureInfo = userContext.UserCulture;
                    }
                }
            }
            if (cultureInfo != null)
            {
                Culture.InternalSetThreadPreferredCulture(cultureInfo);
            }
            else
            {
                Culture.InternalSetThreadPreferredCulture();
            }
            return(DispatchStepResult.Continue);
        }
示例#11
0
        private static DispatchStepResult InternalDispatchRequest(RequestContext requestContext)
        {
            HttpRequest request = requestContext.HttpContext.Request;

            requestContext.RequestType = RequestDispatcherUtilities.GetRequestType(request);
            ExTraceGlobals.CoreCallTracer.TraceDebug <OwaRequestType>(0L, "[RequestDispatcher::InternalDispatchRequest] Processing requestType={0}.", requestContext.RequestType);
            OwaRequestType requestType = requestContext.RequestType;

            if (requestType <= OwaRequestType.LanguagePage)
            {
                switch (requestType)
                {
                case OwaRequestType.Invalid:
                    requestContext.HttpStatusCode = HttpStatusCode.BadRequest;
                    return(DispatchStepResult.EndResponse);

                case OwaRequestType.Authorize:
                    break;

                case OwaRequestType.Logoff:
                case OwaRequestType.Aspx:
                    goto IL_C2;

                case OwaRequestType.EsoRequest:
                    return(DispatchStepResult.Stop);

                default:
                    switch (requestType)
                    {
                    case OwaRequestType.ProxyPing:
                        RequestDispatcherUtilities.RespondProxyPing(requestContext);
                        return(DispatchStepResult.EndResponse);

                    case OwaRequestType.LanguagePage:
                        break;

                    default:
                        goto IL_C2;
                    }
                    break;
                }
                requestContext.HttpContext.Response.AppendHeader("X-OWA-Version", Globals.ApplicationVersion);
                return(DispatchStepResult.Stop);
            }
            if (requestType == OwaRequestType.Resource)
            {
                return(DispatchStepResult.Stop);
            }
            switch (requestType)
            {
            case OwaRequestType.WopiRequest:
                return(DispatchStepResult.Stop);

            case OwaRequestType.RemoteNotificationRequest:
                return(DispatchStepResult.Stop);

            case OwaRequestType.GroupSubscriptionRequest:
                return(DispatchStepResult.Stop);
            }
IL_C2:
            if (!requestContext.HttpContext.Request.IsAuthenticated)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::InternalDispatchRequest] Request not authenticated. returning.");
                requestContext.HttpStatusCode = HttpStatusCode.Unauthorized;
                return(DispatchStepResult.EndResponse);
            }
            DispatchStepResult dispatchStepResult = RequestDispatcher.DispatchIfLogoffRequest(requestContext);

            if (dispatchStepResult != DispatchStepResult.Continue)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::InternalDispatchRequest] DispatchIfLogoffRequest returned {0}. returning.", dispatchStepResult);
                return(dispatchStepResult);
            }
            dispatchStepResult = RequestDispatcher.DispatchIfLastPendingGet(requestContext);
            if (dispatchStepResult != DispatchStepResult.Continue)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::InternalDispatchRequest] DispatchIfLastPendingGet returned {0}. returning.", dispatchStepResult);
                return(dispatchStepResult);
            }
            dispatchStepResult = RequestDispatcher.DispatchIfGetUserPhotoRequest(requestContext);
            if (dispatchStepResult != DispatchStepResult.Continue)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::InternalDispatchRequest] DispatchIfGetUserPhotoRequest returned {0}. returning.", dispatchStepResult);
                return(dispatchStepResult);
            }
            requestContext.UserContext = UserContextManager.GetMailboxContext(requestContext.HttpContext, null, true);
            if (!requestContext.UserContext.ExchangePrincipal.MailboxInfo.Configuration.IsOwaEnabled && !OfflineClientRequestUtilities.IsRequestFromMOWAClient(requestContext.HttpContext.Request, requestContext.HttpContext.Request.UserAgent))
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::InternalDispatchRequest] OWA Disabled: redirecting to error page.");
                throw new AccountDisabledException(new LocalizedString(Strings.GetLocalizedString(531497785)));
            }
            if (RequestDispatcher.ShouldBlockConnection(requestContext.HttpContext, requestContext.UserContext.LogonIdentity))
            {
                ExTraceGlobals.CoreCallTracer.TraceWarning <string>(0L, "[RequestDispatcher::InternalOnPostAuthorizeRequest] blocked by Client Access Rules. Request URL={0}.", requestContext.HttpContext.Request.Url.OriginalString);
                if (requestContext.UserContext.LogonIdentity.UserOrganizationId != null && !OrganizationId.ForestWideOrgId.Equals(requestContext.UserContext.LogonIdentity.UserOrganizationId))
                {
                    requestContext.DestinationUrl = OwaUrl.LogoffPageBlockedByClientAccessRules.GetExplicitUrl(requestContext.HttpContext.Request);
                }
                else
                {
                    requestContext.DestinationUrl = OwaUrl.LogoffBlockedByClientAccessRules.GetExplicitUrl(requestContext.HttpContext.Request);
                }
                return(DispatchStepResult.RedirectToUrl);
            }
            dispatchStepResult = RequestDispatcher.ValidateExplicitLogonPermissions(requestContext);
            if (dispatchStepResult != DispatchStepResult.Continue)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::InternalDispatchRequest] ValidateExplicitLogonPermissions returned {0}. returning.", dispatchStepResult);
                return(dispatchStepResult);
            }
            dispatchStepResult = RequestDispatcher.DispatchIfLanguagePost(requestContext);
            if (dispatchStepResult != DispatchStepResult.Continue)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::InternalDispatchRequest] DispatchIfLanguagePost returned {0}. returning.", dispatchStepResult);
                return(dispatchStepResult);
            }
            if (requestContext.UserContext is UserContext)
            {
                dispatchStepResult = RequestDispatcher.ValidateAndSetThreadCulture(requestContext);
                if (dispatchStepResult != DispatchStepResult.Continue)
                {
                    ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::InternalDispatchRequest] ValidateAndSetThreadCulture returned {0}. returning.", dispatchStepResult);
                    return(dispatchStepResult);
                }
            }
            Uri originalRequestUrlFromContext = UrlUtilities.GetOriginalRequestUrlFromContext(requestContext.HttpContext);

            dispatchStepResult = RequestDispatcher.SendAppCacheRedirect(requestContext, originalRequestUrlFromContext);
            if (dispatchStepResult != DispatchStepResult.Continue)
            {
                ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::InternalDispatchRequest] SendAppCacheRedirect returned {0}. returning.", dispatchStepResult);
                return(dispatchStepResult);
            }
            requestContext.HttpContext.Response.AppendHeader("X-OWA-Version", Globals.ApplicationVersion);
            requestContext.HttpContext.Response.AppendHeader("X-OWA-OWSVersion", ExchangeVersion.Latest.Version.ToString());
            requestContext.HttpContext.Response.AppendHeader("X-OWA-MinimumSupportedOWSVersion", ExchangeVersionType.V2_6.ToString());
            RequestDispatcher.SetTimeoutForRequest(requestContext.HttpContext, requestContext.RequestType);
            RequestDispatcher.CheckAndAddHostNameChangedCookie(requestContext, request);
            return(RequestDispatcher.DoFinalDispatch(requestContext));
        }
        private void InternalAfterReceiveRequest(HttpRequest httpRequest, string methodName, object request)
        {
            try
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug <string>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] called for method name: {0}", methodName);
                CallContext.ClearCallContextForCurrentThread();
                Globals.UpdateErrorTracingConfiguration();
                OwaApplication.GetRequestDetailsLogger.ActivityScope.SetProperty(ExtensibleLoggerMetadata.EventId, methodName);
                OwaServiceMessage message = new OwaServiceMessage(httpRequest, request);
                message.Headers.Action = methodName;
                message.Properties["HttpOperationName"] = methodName;
                OwaMessageHeaderProcessor messageHeaderProcessor = new OwaMessageHeaderProcessor();
                bool flag  = OWAMessageInspector.RequestNeedsHeaderProcessing(methodName);
                bool flag2 = OWAMessageInspector.RequestNeedsQueryStringProcessing(methodName);
                bool flag3 = OWAMessageInspector.RequestNeedsHttpHeaderProcessing(methodName);
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] processing message headers");
                if (flag || flag2 || flag3)
                {
                    if (flag)
                    {
                        messageHeaderProcessor.ProcessMessageHeaders(message);
                        messageHeaderProcessor.ProcessEwsVersionFromHttpHeaders(message);
                    }
                    else if (flag2)
                    {
                        messageHeaderProcessor.ProcessMessageHeadersFromQueryString(message);
                    }
                    else if (flag3)
                    {
                        messageHeaderProcessor.ProcessHttpHeaders(message, ExchangeVersion.Exchange2013);
                    }
                }
                message.Properties["MessageHeaderProcessor"] = messageHeaderProcessor;
                message.Properties["ConnectionCostType"]     = 0;
                WebMethodEntry jsonWebMethodEntry;
                if (!OWAMessageInspector.MethodNameToWebMethodEntryMap.Member.TryGetValue(methodName, out jsonWebMethodEntry))
                {
                    jsonWebMethodEntry = WebMethodEntry.JsonWebMethodEntry;
                }
                message.Properties["WebMethodEntry"] = jsonWebMethodEntry;
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] creating CallContext");
                CallContext callContext = OwaApplication.GetRequestDetailsLogger.TrackLatency <CallContext>(ServiceLatencyMetadata.CallContextInitLatency, () => CallContextUtilities.CreateCallContext(message, messageHeaderProcessor, true, ""));
                callContext.IsOwa = true;
                ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] CallContext created");
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsMowaClient, OfflineClientRequestUtilities.IsRequestFromMOWAClient(callContext.HttpContext.Request, callContext.HttpContext.Request.UserAgent) ? 1 : 0);
                bool?flag4 = new bool?(OfflineClientRequestUtilities.IsRequestFromOfflineClient(callContext.HttpContext.Request));
                if (flag4 != null)
                {
                    callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.IsOfflineEnabled, flag4.Value ? 1 : 0);
                }
                callContext.OwaExplicitLogonUser = UserContextUtilities.GetExplicitLogonUser(HttpContext.Current);
                if (string.IsNullOrEmpty(callContext.OwaExplicitLogonUser))
                {
                    OWAMessageInspector.CheckThatUserProvisionedDevice(methodName, callContext);
                    OWAMessageInspector.CheckMowaRemoteWipe(methodName, callContext);
                    OWAMessageInspector.CheckClientVersion(callContext);
                    OWAMessageInspector.CheckMowaDisabled(callContext);
                    OWAMessageInspector.CheckMobileDevicePolicyIsCorrect(methodName, callContext);
                }
                OWAMessageInspector.MarkResponseNonCacheable(methodName);
                callContext.WorkloadType       = WorkloadType.Owa;
                callContext.UsingWcfDispatcher = false;
                callContext.ProtocolLog.Set(OwaServerLogger.LoggerData.UsingWcfHttpHandler, 0);
                if (ExchangeVersion.Current == ExchangeVersion.Exchange2007)
                {
                    ExchangeVersion.Current = ExchangeVersion.Exchange2013;
                }
                if (OWAMessageInspector.ShouldCreateUserContext(callContext))
                {
                    UserContext userContext = UserContextManager.GetMailboxContext(callContext.HttpContext, callContext.EffectiveCaller, true) as UserContext;
                    if (userContext != null)
                    {
                        callContext.OwaCulture = userContext.UserCulture;
                        if (userContext.FeaturesManager != null)
                        {
                            callContext.FeaturesManager = userContext.FeaturesManager;
                            if (userContext.FeaturesManager.ServerSettings.OwaMailboxSessionCloning.Enabled)
                            {
                                callContext.OwaUserContextKey = userContext.Key.ToString();
                            }
                        }
                    }
                }
            }
            catch (LocalizedException ex)
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, LocalizedException>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught localized exception trying to process message. Type: {0} Exception: {1}", ex.GetType().Name, ex);
                OwaServerTraceLogger.AppendToLog(new TraceLogEvent("OWAMessageInspector", null, "InternalAfterReceiveRequest", string.Format("OwaServiceFaultException_InnerException - {0}", ex)));
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex, "OwaServiceFaultException_InnerException");

                throw OwaFaultExceptionUtilities.CreateFault(ex);
            }
            catch (Exception ex2)
            {
                ExTraceGlobals.CommonAlgorithmTracer.TraceError <string, Exception>((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] Caught exception trying to process message. Type: {0} Exception: {1}", ex2.GetType().Name, ex2);
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeLogRequestException(OwaApplication.GetRequestDetailsLogger, ex2, "OwaServiceFaultException_InnerException");

                throw;
            }
            ExTraceGlobals.CommonAlgorithmTracer.TraceDebug((long)this.GetHashCode(), "[OwaServiceMessageInspector::InternalAfterReceiveRequest] completed");
        }