Пример #1
0
        private static void BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;
            HttpRequest     request     = context.Request;
            HttpResponse    response    = context.Response;
            string          url         = context.Request.Url.AbsolutePath;

            using (new Tracer(sender, e, url))
            {
                // Attempt to determine Localization
                try
                {
                    Localization localization = WebRequestContext.Localization;
                    Log.Debug("Request URL '{0}' maps to Localization [{1}]", request.Url, localization);
                }
                catch (DxaUnknownLocalizationException ex)
                {
                    SendNotFoundResponse(ex.Message, response);
                }
                catch (DxaItemNotFoundException ex)
                {
                    // Localization has been resolved, but could not be initialized (e.g. Version.json not found)
                    Log.Error(ex);
                    SendNotFoundResponse(ex.Message, response);
                }
                catch (Exception ex)
                {
                    // Other exceptions: log and let ASP.NET handle them
                    Log.Error(ex);
                    throw;
                }


                // Prevent direct access to BinaryData folder
                if (url.StartsWith("/" + SiteConfiguration.StaticsFolder + "/"))
                {
                    SendNotFoundResponse(string.Format("Attempt to directly access the static content cache through URL '{0}'", url), response);
                }

                // Rewrite versioned URLs
                string versionLessUrl = SiteConfiguration.RemoveVersionFromPath(url);
                if (url != versionLessUrl)
                {
                    Log.Debug("Rewriting versioned static content URL '{0}' to '{1}'", url, versionLessUrl);
                    context.RewritePath(versionLessUrl);
                    context.Items[IsVersionedUrlContextItem] = true;
                }
            }
        }
        private static void BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;
            HttpRequest     request     = context.Request;
            HttpResponse    response    = context.Response;
            string          url         = context.Request.Url.AbsolutePath;

            using (new Tracer(sender, e, url))
            {
                // Attempt to determine Localization
                try
                {
                    Localization localization = WebRequestContext.Localization;
                    Log.Debug("Request URL '{0}' maps to Localization [{1}]", request.Url, localization);
                }
                catch (DxaUnknownLocalizationException ex)
                {
                    SendNotFoundResponse(ex.Message, response);
                }

                // Prevent direct access to BinaryData folder
                if (url.StartsWith("/" + SiteConfiguration.StaticsFolder + "/"))
                {
                    SendNotFoundResponse(string.Format("Attempt to directly access the static content cache through URL '{0}'", url), response);
                }

                // Rewrite versioned URLs
                string versionLessUrl = SiteConfiguration.RemoveVersionFromPath(url);
                if (url != versionLessUrl)
                {
                    Log.Debug("Rewriting versioned static content URL '{0}' to '{1}'", url, versionLessUrl);
                    context.RewritePath(versionLessUrl);
                }
            }
        }
Пример #3
0
        private static void BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;
            HttpRequest     request     = context.Request;
            HttpResponse    response    = context.Response;
            string          url         = request.Url.AbsolutePath;

            using (new Tracer(sender, e, url))
            {
                // If DXA fails to initialize due to no TTM mapping then we can still identify if DXA is running by going to /system/health
                if (url.EndsWith("/system/health"))
                {
                    SendHealthCheckResponse(response);
                }
                // Attempt to determine Localization
                ILocalization localization = null;
                try
                {
                    localization = WebRequestContext.Localization;
                }
                catch (DxaUnknownLocalizationException ex)
                {
                    IUnknownLocalizationHandler unknownLocalizationHandler = SiteConfiguration.UnknownLocalizationHandler;
                    if (unknownLocalizationHandler != null)
                    {
                        localization = unknownLocalizationHandler.HandleUnknownLocalization(ex, request, response);
                    }

                    if (localization == null)
                    {
                        // There was no Unknown Localization Handler or it didn't terminate the request processing using response.End()
                        // and it also didn't resolve a Localization.
                        SendNotFoundResponse(ex.Message, response);
                    }
                }
                catch (DxaItemNotFoundException ex)
                {
                    // Localization has been resolved, but could not be initialized (e.g. Version.json not found)
                    Log.Error(ex);
                    SendNotFoundResponse(ex.Message, response);
                }
                catch (Exception ex)
                {
                    // Other exceptions: log and let ASP.NET handle them
                    Log.Error(ex);
                    throw;
                }
                Log.Debug("Request URL '{0}' maps to Localization [{1}]", request.Url, localization);

                // Prevent direct access to BinaryData folder
                if (url.StartsWith("/" + SiteConfiguration.StaticsFolder + "/"))
                {
                    SendNotFoundResponse(string.Format("Attempt to directly access the static content cache through URL '{0}'", url), response);
                }

                // Rewrite versioned URLs
                string versionLessUrl = SiteConfiguration.RemoveVersionFromPath(url);
                if (url != versionLessUrl)
                {
                    Log.Debug("Rewriting versioned static content URL '{0}' to '{1}'", url, versionLessUrl);
                    context.RewritePath(versionLessUrl);
                    context.Items[IsVersionedUrlContextItem] = true;
                }
            }
        }