Esempio n. 1
0
        private void AppendMetaTags(ref StringWriter writer)
        {
            bool isContentTypeAdded = false, isPragmaAdded = false, isCacheControlAdded = false, isExpiresAdded = false;

            foreach (var(key, value) in this._DomainControl.MetaRecord.CommonTags)
            {
                switch (Basics.MetaRecord.QueryTagSpace(key))
                {
                case Basics.MetaRecord.TagSpaces.name:
                    writer.WriteLine(
                        $"<meta name=\"{Basics.MetaRecord.GetTagHtmlName(key)}\" content=\"{value}\" />"
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.httpequiv:
                    writer.WriteLine(
                        $"<meta http-equiv=\"{Basics.MetaRecord.GetTagHtmlName(key)}\" content=\"{value}\" />"
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.property:
                    writer.WriteLine(
                        $"<meta property=\"{Basics.MetaRecord.GetTagHtmlName(key)}\" content=\"{value}\" />"
                        );

                    break;
                }

                switch (key)
                {
                case Basics.MetaRecord.Tags.contenttype:
                    isContentTypeAdded = true;

                    break;

                case Basics.MetaRecord.Tags.pragma:
                    isPragmaAdded = true;

                    break;

                case Basics.MetaRecord.Tags.cachecontrol:
                    isCacheControlAdded = true;

                    break;

                case Basics.MetaRecord.Tags.expires:
                    isExpiresAdded = true;

                    break;
                }
            }

            foreach (var(key, value) in this._DomainControl.MetaRecord.CustomTags)
            {
                string keyName = key;
                switch (Basics.MetaRecord.QueryTagSpace(ref keyName))
                {
                case Basics.MetaRecord.TagSpaces.name:
                    writer.WriteLine(
                        $"<meta name=\"{keyName}\" content=\"{value}\" />"
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.httpequiv:
                    writer.WriteLine(
                        $"<meta http-equiv=\"{keyName}\" content=\"{value}\" />"
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.property:
                    writer.WriteLine(
                        $"<meta property=\"{keyName}\" content=\"{value}\" />"
                        );

                    break;
                }
            }

            if (!isContentTypeAdded)
            {
                writer.WriteLine(
                    "<meta http-equiv=\"Content-Type\" content=\"{0}; charset={1}\" />",
                    this._DomainControl.ServiceMimeType, Encoding.UTF8.WebName);
            }

            Basics.Enum.PageCachingTypes defaultType =
                this._DomainControl.Domain.Settings.Configurations.DefaultCaching;

            if (defaultType != Basics.Enum.PageCachingTypes.NoCache &&
                defaultType != Basics.Enum.PageCachingTypes.NoCacheCookieless)
            {
                return;
            }

            if (!isPragmaAdded)
            {
                writer.WriteLine("<meta http-equiv=\"Pragma\" content=\"no-cache\" />");
            }
            if (!isCacheControlAdded)
            {
                writer.WriteLine("<meta http-equiv=\"Cache-Control\" content=\"no-cache\" />");
            }
            if (!isExpiresAdded)
            {
                writer.WriteLine("<meta http-equiv=\"Expires\" content=\"0\" />");
            }
        }
Esempio n. 2
0
        public void Handle()
        {
            this._BeginRequestTime   = DateTime.Now;
            this._SupportCompression = false;

            try
            {
                if (this._ForceRefresh)
                {
                    Application.DomainControl.ClearCache();
                }

                IHttpContext context = this.Context;
                this._DomainControl = new DomainControl(ref context);

                Basics.Enum.PageCachingTypes defaultCaching =
                    this._DomainControl.Domain.Settings.Configurations.DefaultCaching;

                // Caching Settings
                if (defaultCaching != Basics.Enum.PageCachingTypes.AllContent &&
                    defaultCaching != Basics.Enum.PageCachingTypes.AllContentCookieless)
                {
                    switch (defaultCaching)
                    {
                    case Basics.Enum.PageCachingTypes.NoCache:
                    case Basics.Enum.PageCachingTypes.NoCacheCookieless:
                        this.Context.Response.Header.AddOrUpdate("Cache-Control", "no-store, must-revalidate");

                        break;

                    default:
                        this.Context.Response.Header.AddOrUpdate("Cache-Control", "no-cache");
                        this.Context.Response.Header.AddOrUpdate("Pragma", "no-cache");

                        break;
                    }

                    this.Context.Response.Header.AddOrUpdate("Expires", "0");
                }
                else
                {
                    this.Context.Response.Header.AddOrUpdate("Expires", DateTime.Now.AddMonths(1).ToString("r"));
                }
                // !---

                string acceptEncodings = this.Context.Request.Header["Accept-Encoding"];
                if (Configurations.Xeora.Application.Main.Compression && acceptEncodings != null)
                {
                    this._SupportCompression = acceptEncodings.IndexOf("gzip", StringComparison.Ordinal) > -1;
                }

                if (this._DomainControl.ServiceDefinition == null)
                {
                    this.HandleStaticFile(); // Static File that has the same level of Application folder or Domain Content File
                }
                else
                {
                    this.HandleServiceRequest(); // Service Request (Template, xService, xSocket)
                }
            }
            catch (Exception ex)
            {
                this.Context.Response.Header.Status.Code = 500;

                this.HandleErrorLogging(ex);
            }
            finally
            {
                // If Redirection has been assigned, handle it
                if (this.Context["RedirectLocation"] != null)
                {
                    if (((string)this.Context["RedirectLocation"]).IndexOf("://", StringComparison.InvariantCulture) == -1)
                    {
                        string redirectLocation =
                            $"{(Configurations.Xeora.Service.Ssl ? "https" : "http")}://{this.Context.Request.Header.Host}{this.Context["RedirectLocation"]}";

                        this.Context.AddOrUpdate("RedirectLocation", redirectLocation);
                    }

                    if (this.Context.Request.Header["X-BlockRenderingId"] == null)
                    {
                        this.Context.Response.Redirect((string)this.Context["RedirectLocation"]);
                    }
                    else
                    {
                        this.Context.Response.Header.Status.Code = 200;

                        byte[] redirectBytes =
                            Encoding.UTF8.GetBytes($"rl:{(string) this.Context["RedirectLocation"]}");

                        this.Context.Response.Header.AddOrUpdate("Content-Type", "text/html");
                        this.Context.Response.Header.AddOrUpdate("Content-Encoding", "identity");

                        this.Context.Response.Write(redirectBytes, 0, redirectBytes.Length);
                    }
                }
            }
        }
Esempio n. 3
0
        private void AppendMetaTags(ref StringWriter writer)
        {
            bool isContentTypeAdded = false, isPragmaAdded = false, isCacheControlAdded = false, isExpiresAdded = false;

            foreach (KeyValuePair <Basics.MetaRecord.Tags, string> kVP in this._DomainControl.MetaRecord.CommonTags)
            {
                switch (Basics.MetaRecord.QueryTagSpace(kVP.Key))
                {
                case Basics.MetaRecord.TagSpaces.name:
                    writer.WriteLine(
                        string.Format(
                            "<meta name=\"{0}\" content=\"{1}\" />",
                            Basics.MetaRecord.GetTagHtmlName(kVP.Key),
                            kVP.Value
                            )
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.httpequiv:
                    writer.WriteLine(
                        string.Format(
                            "<meta http-equiv=\"{0}\" content=\"{1}\" />",
                            Basics.MetaRecord.GetTagHtmlName(kVP.Key),
                            kVP.Value
                            )
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.property:
                    writer.WriteLine(
                        string.Format(
                            "<meta property=\"{0}\" content=\"{1}\" />",
                            Basics.MetaRecord.GetTagHtmlName(kVP.Key),
                            kVP.Value
                            )
                        );

                    break;
                }

                switch (kVP.Key)
                {
                case Basics.MetaRecord.Tags.contenttype:
                    isContentTypeAdded = true;

                    break;

                case Basics.MetaRecord.Tags.pragma:
                    isPragmaAdded = true;

                    break;

                case Basics.MetaRecord.Tags.cachecontrol:
                    isCacheControlAdded = true;

                    break;

                case Basics.MetaRecord.Tags.expires:
                    isExpiresAdded = true;

                    break;
                }
            }

            string keyName = string.Empty;

            foreach (KeyValuePair <string, string> kVP in this._DomainControl.MetaRecord.CustomTags)
            {
                keyName = kVP.Key;
                switch (Basics.MetaRecord.QueryTagSpace(ref keyName))
                {
                case Basics.MetaRecord.TagSpaces.name:
                    writer.WriteLine(
                        string.Format(
                            "<meta name=\"{0}\" content=\"{1}\" />",
                            keyName,
                            kVP.Value
                            )
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.httpequiv:
                    writer.WriteLine(
                        string.Format(
                            "<meta http-equiv=\"{0}\" content=\"{1}\" />",
                            keyName,
                            kVP.Value
                            )
                        );

                    break;

                case Basics.MetaRecord.TagSpaces.property:
                    writer.WriteLine(
                        string.Format(
                            "<meta property=\"{0}\" content=\"{1}\" />",
                            keyName,
                            kVP.Value
                            )
                        );

                    break;
                }
            }

            if (!isContentTypeAdded)
            {
                writer.WriteLine(
                    string.Format(
                        "<meta http-equiv=\"Content-Type\" content=\"{0}; charset={1}\" />",
                        this._DomainControl.ServiceMimeType,
                        Encoding.UTF8.WebName
                        )
                    );
            }

            Basics.Enum.PageCachingTypes defaultType =
                this._DomainControl.Domain.Settings.Configurations.DefaultCaching;

            if (defaultType == Basics.Enum.PageCachingTypes.NoCache || defaultType == Basics.Enum.PageCachingTypes.NoCacheCookiless)
            {
                if (!isPragmaAdded)
                {
                    writer.WriteLine("<meta http-equiv=\"Pragma\" content=\"no-cache\" />");
                }
                if (!isCacheControlAdded)
                {
                    writer.WriteLine("<meta http-equiv=\"Cache-Control\" content=\"no-cache\" />");
                }
                if (!isExpiresAdded)
                {
                    writer.WriteLine("<meta http-equiv=\"Expires\" content=\"0\" />");
                }
            }
        }