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));
        }