Exemplo n.º 1
0
        // Token: 0x060010D2 RID: 4306 RVA: 0x0003FFF0 File Offset: 0x0003E1F0
        public IHttpHandler GetHandler(HttpContext httpContext, string requestType, string url, string pathTranslated)
        {
            ExTraceGlobals.OehCallTracer.TraceDebug(0L, "OwaEventHandlerFactory.GetHandler");
            string queryStringParameter  = HttpUtilities.GetQueryStringParameter(httpContext.Request, "ns");
            string queryStringParameter2 = HttpUtilities.GetQueryStringParameter(httpContext.Request, "ev");

            ExTraceGlobals.OehDataTracer.TraceDebug <string, string>(0L, "Request namespace: '{0}', event: '{1}'", queryStringParameter, queryStringParameter2);
            HttpApplication  applicationInstance = httpContext.ApplicationInstance;
            OwaEventRegistry owaEventRegistry    = (OwaEventRegistry)applicationInstance.Application["OwaEventRegistry"];

            if (owaEventRegistry == null)
            {
                HttpUtilities.EndResponse(httpContext, HttpStatusCode.MethodNotAllowed);
                return(null);
            }
            OwaEventNamespaceAttribute owaEventNamespaceAttribute = owaEventRegistry.FindNamespaceInfo(queryStringParameter);

            if (owaEventNamespaceAttribute == null)
            {
                throw new OwaException(string.Format(CultureInfo.InvariantCulture, "Namespace '{0}' doesn't exist", new object[]
                {
                    queryStringParameter
                }), null, this);
            }
            OwaEventAttribute owaEventAttribute = owaEventNamespaceAttribute.FindEventInfo(queryStringParameter2);

            if (owaEventAttribute == null)
            {
                throw new OwaException(string.Format(CultureInfo.InvariantCulture, "Event '{0}' doesn't exist", new object[]
                {
                    queryStringParameter2
                }), null, this);
            }
            OwaEventVerb owaEventVerb = OwaEventVerbAttribute.Parse(httpContext.Request.HttpMethod);

            ExTraceGlobals.OehDataTracer.TraceDebug <string>(0L, "Request verb: {0}", httpContext.Request.HttpMethod);
            if ((owaEventAttribute.AllowedVerbs & owaEventVerb) == OwaEventVerb.Unsupported)
            {
                ExTraceGlobals.OehTracer.TraceDebug <OwaEventVerb, OwaEventVerb>(0L, "Verb is not allowed, returning 405. Actual verb: {0}. Allowed: {1}.", owaEventVerb, owaEventAttribute.AllowedVerbs);
                HttpUtilities.EndResponse(httpContext, HttpStatusCode.MethodNotAllowed);
                return(null);
            }
            OwaEventHandlerBase owaEventHandlerBase = (OwaEventHandlerBase)Activator.CreateInstance(owaEventNamespaceAttribute.HandlerType);

            owaEventHandlerBase.EventInfo = owaEventAttribute;
            owaEventHandlerBase.Verb      = owaEventVerb;
            if (owaEventAttribute.IsAsync)
            {
                ExTraceGlobals.OehTracer.TraceDebug(0L, "Created async HTTP handler to server OEH request");
                return(new OwaEventAsyncHttpHandler(owaEventHandlerBase));
            }
            return(new OwaEventHttpHandler(owaEventHandlerBase));
        }
Exemplo n.º 2
0
        public static void DispatchRequest(RequestContext requestContext)
        {
            ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::DispatchRequest] entry.");
            HttpContext httpContext = requestContext.HttpContext;

            UrlUtilities.RewriteFederatedDomainInURL(httpContext);
            DispatchStepResult arg = RequestDispatcher.InternalDispatchRequest(requestContext);

            ExTraceGlobals.CoreCallTracer.TraceDebug <DispatchStepResult>(0L, "[RequestDispatcher::DispatchRequest] Last dispatch step result={0}.", arg);
            switch (arg)
            {
            case DispatchStepResult.RedirectToUrl:
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>(0L, "[RequestDispatcher::DispatchRequest] Redirecting response to '{0}'.", requestContext.DestinationUrl);
                httpContext.Response.Redirect(requestContext.DestinationUrl, false);
                if (requestContext.RequestType != OwaRequestType.Logoff || !RequestDispatcherUtilities.IsDownLevelClient(requestContext.HttpContext, false))
                {
                    httpContext.ApplicationInstance.CompleteRequest();
                }
                return;

            case DispatchStepResult.RewritePath:
                ExTraceGlobals.CoreCallTracer.TraceDebug <string>(0L, "[RequestDispatcher::DispatchRequest] Rewriting path to '{0}'.", requestContext.DestinationUrl);
                if (string.IsNullOrEmpty(requestContext.DestinationUrlQueryString))
                {
                    httpContext.RewritePath(requestContext.DestinationUrl);
                    return;
                }
                httpContext.RewritePath(requestContext.DestinationUrl, null, requestContext.DestinationUrlQueryString);
                break;

            case DispatchStepResult.RewritePathToError:
            case DispatchStepResult.Continue:
                break;

            case DispatchStepResult.EndResponse:
                ExTraceGlobals.CoreCallTracer.TraceDebug <int>(0L, "[RequestDispatcher::DispatchRequest] Ending response with statusCode={0}.", (int)requestContext.HttpStatusCode);
                HttpUtilities.EndResponse(requestContext.HttpContext, requestContext.HttpStatusCode);
                return;

            case DispatchStepResult.EndResponseWithPrivateCaching:
                ExTraceGlobals.CoreCallTracer.TraceDebug <int>(0L, "[RequestDispatcher::DispatchRequest] Ending response with statusCode={0} and PRIVATE cacheability.", (int)requestContext.HttpStatusCode);
                HttpUtilities.EndResponse(requestContext.HttpContext, requestContext.HttpStatusCode, HttpCacheability.Private);
                return;

            case DispatchStepResult.Stop:
                ExTraceGlobals.CoreCallTracer.TraceDebug(0L, "[RequestDispatcher::DispatchRequest] Stopped the dispatching of this request.");
                return;

            default:
                return;
            }
        }
 // Token: 0x0600108D RID: 4237 RVA: 0x0003F714 File Offset: 0x0003D914
 public static void EndResponse(HttpContext httpContext, HttpStatusCode statusCode)
 {
     HttpUtilities.EndResponse(httpContext, statusCode, HttpCacheability.NoCache);
 }
        // Token: 0x0600097E RID: 2430 RVA: 0x00020CF4 File Offset: 0x0001EEF4
        internal static void HandleException(RequestContext requestContext, Exception exception)
        {
            if (exception is HttpException && (exception.InnerException is SlabManifestException || exception.InnerException is FlightConfigurationException))
            {
                exception = exception.InnerException;
            }
            ErrorHandlerUtilities.RecordException(requestContext, exception);
            ExTraceGlobals.CoreTracer.TraceDebug <Type, Exception>(0L, "Exception: Type: {0} Error: {1}.", exception.GetType(), exception);
            HttpContext httpContext = requestContext.HttpContext;

            HttpUtilities.MakePageNoCacheNoStore(httpContext.Response);
            if (exception is HttpException)
            {
                HttpUtilities.EndResponse(httpContext, HttpStatusCode.BadRequest);
                return;
            }
            if (exception is OwaInvalidRequestException || exception is OwaInvalidIdFormatException)
            {
                HttpUtilities.EndResponse(httpContext, HttpStatusCode.BadRequest);
                return;
            }
            if (exception is MailboxInSiteFailoverException && requestContext.UserContext != null)
            {
                ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "User {0}'s mailbox in-site failover occurs.", requestContext.UserContext.ExchangePrincipal.LegacyDn);
                if (requestContext.UserContext != null)
                {
                    requestContext.UserContext.DisconnectMailboxSession();
                }
            }
            if (exception is MailboxCrossSiteFailoverException || exception is WrongServerException)
            {
                if (requestContext.UserContext != null)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "User {0}'s mailbox cross-site failover occurs.", requestContext.UserContext.ExchangePrincipal.LegacyDn);
                }
                UserContextCookie userContextCookie = UserContextCookie.GetUserContextCookie(httpContext);
                if (userContextCookie != null)
                {
                    HttpUtilities.DeleteCookie(httpContext.Response, userContextCookie.CookieName);
                }
            }
            if (exception is OverBudgetException)
            {
                OverBudgetException ex = (OverBudgetException)exception;
                httpContext.Response.AppendToLog(string.Format("&OverBudget({0}/{1}),Owner:{2}[{3}]", new object[]
                {
                    ex.IsServiceAccountBudget ? "ServiceAccount" : "Normal",
                    ex.PolicyPart,
                    ex.Owner,
                    ex.Snapshot
                }));
            }
            ErrorInformation exceptionHandlingInformation = ErrorHandlerUtilities.GetExceptionHandlingInformation(exception, requestContext);

            try
            {
                if (!requestContext.ErrorSent)
                {
                    requestContext.ErrorSent = true;
                    httpContext.Response.Clear();
                    try
                    {
                        if (RequestDispatcherUtilities.GetRequestType(httpContext.Request) != OwaRequestType.ServiceRequest && RequestDispatcherUtilities.GetRequestType(httpContext.Request) != OwaRequestType.Oeh && !httpContext.Request.Path.Contains(OwaUrl.SessionDataPage.ImplicitUrl))
                        {
                            StringBuilder stringBuilder = new StringBuilder("/owa/auth/errorfe.aspx");
                            stringBuilder.Append("?");
                            stringBuilder.Append("httpCode");
                            stringBuilder.Append("=");
                            stringBuilder.Append(500);
                            if (exceptionHandlingInformation.SharePointApp)
                            {
                                stringBuilder.Append("&sharepointapp=true");
                            }
                            if (exceptionHandlingInformation.SiteMailbox)
                            {
                                stringBuilder.Append("&sm=true");
                            }
                            if (exceptionHandlingInformation.GroupMailboxDestination != null)
                            {
                                stringBuilder.Append("&gm=");
                                stringBuilder.Append(HttpUtility.UrlEncode(exceptionHandlingInformation.GroupMailboxDestination));
                            }
                            if (exceptionHandlingInformation.MessageId != null)
                            {
                                stringBuilder.Append("&");
                                stringBuilder.Append("msg");
                                stringBuilder.Append("=");
                                stringBuilder.Append((long)exceptionHandlingInformation.MessageId.Value);
                                if (!string.IsNullOrWhiteSpace(exceptionHandlingInformation.MessageParameter))
                                {
                                    stringBuilder.Append("&");
                                    stringBuilder.Append("msgParam");
                                    stringBuilder.Append("=");
                                    stringBuilder.Append(HttpUtility.UrlEncode(exceptionHandlingInformation.MessageParameter));
                                }
                            }
                            if (!string.IsNullOrWhiteSpace(httpContext.Response.Headers["X-OWA-Error"]))
                            {
                                stringBuilder.Append("&owaError=");
                                stringBuilder.Append(httpContext.Response.Headers["X-OWA-Error"]);
                            }
                            stringBuilder.Append("&owaVer=");
                            stringBuilder.Append(Globals.ApplicationVersion);
                            stringBuilder.Append("&be=");
                            stringBuilder.Append(Environment.MachineName);
                            stringBuilder.Append("&ts=");
                            stringBuilder.Append(DateTime.UtcNow.ToFileTimeUtc());
                            if (!string.IsNullOrWhiteSpace(exceptionHandlingInformation.Lids))
                            {
                                httpContext.Response.AppendToLog(string.Format("&lids={0}", exceptionHandlingInformation.Lids));
                            }
                            if (exceptionHandlingInformation.SupportLevel != null && exceptionHandlingInformation.SupportLevel != SupportLevel.Unknown)
                            {
                                httpContext.Response.AppendHeader("X-OWASuppLevel", exceptionHandlingInformation.SupportLevel.ToString());
                                httpContext.Response.AppendToLog(string.Format("&{0}={1}", "suplvl", exceptionHandlingInformation.SupportLevel.ToString()));
                            }
                            httpContext.Response.Redirect(stringBuilder.ToString(), false);
                        }
                        else
                        {
                            httpContext.Response.Write(exceptionHandlingInformation.Message);
                            httpContext.Response.StatusCode = 500;
                            if (exceptionHandlingInformation.MessageId != null)
                            {
                                httpContext.Response.AddHeader(WellKnownHeader.XOWAErrorMessageID, exceptionHandlingInformation.MessageId.ToString());
                            }
                            httpContext.Response.TrySkipIisCustomErrors = true;
                            httpContext.Response.Flush();
                        }
                        httpContext.ApplicationInstance.CompleteRequest();
                    }
                    catch (HttpException arg)
                    {
                        ExTraceGlobals.CoreTracer.TraceDebug <HttpException>(0L, "Failed to flush and send response to client after submitting watson and rendering error page. {0}", arg);
                    }
                }
            }
            finally
            {
                if (exceptionHandlingInformation.SendWatsonReport && Globals.SendWatsonReports)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug(0L, "Sending watson report");
                    ReportOptions options = (exception is AccessViolationException || exception is InvalidProgramException || exception is TypeInitializationException) ? ReportOptions.ReportTerminateAfterSend : ReportOptions.None;
                    ExWatson.SendReport(exception, options, null);
                }
                if (exception is AccessViolationException)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug(0L, "Shutting down OWA due to unrecoverable exception");
                    ErrorHandlerUtilities.TerminateProcess();
                }
                else if ((exception is InvalidProgramException || exception is TypeInitializationException) && Interlocked.Exchange(ref ErrorHandlerUtilities.queuedDelayedRestart, 1) == 0)
                {
                    new Thread(new ThreadStart(ErrorHandlerUtilities.DelayedRestartUponUnexecutableCode)).Start();
                }
                httpContext.Response.End();
            }
        }