예제 #1
0
        private T GetVirtualContextItem <T>(string key)
        {
            object value = VirtualContext.GetItem(key);

            if (value != null)
            {
                return((T)value);
            }

            return(default(T));
        }
예제 #2
0
        private void HandleBeginRequest(object sender, EventArgs e)
        {
            var application      = (HttpApplication)sender;
            var context          = application.Context;
            var relativeFilePath = context.Request.AppRelativeCurrentExecutionFilePath.TrimStart('~');

            // Check whether the current request URL contains information about a preview mode
            if (HandleVirtualContext(ref relativeFilePath))
            {
                // Validate integrity of preview information (including the unique identifier generated by Kentico) in the current request URL
                if (!VirtualContext.ValidatePreviewHash(relativeFilePath) || !ValidatePreviewGuid(VirtualContext.GetItem(VirtualContext.PARAM_WF_GUID)))
                {
                    VirtualContext.Reset();
                    throw new HttpException(404, "The preview link is not valid.");
                }

                // Disable same origin policy for a preview mode as Kentico displays preview in a frame
                AntiForgeryConfig.SuppressXFrameOptionsHeader = true;

                // Do not cache response in a preview mode, it has to contain current data
                context.Response.Cache.SetNoServerCaching();
                context.Response.Cache.SetNoStore();

                // Remove preview mode information from the request URL
                context.RewritePath("~" + relativeFilePath, context.Request.PathInfo, context.Request.Url.Query.TrimStart('?'));
            }

            var previewFeature = new PreviewFeature();

            context.Kentico().SetFeature <IPreviewFeature>(previewFeature);
        }