Esempio n. 1
0
 public static void SetCookie(HttpCookie cookie)
 {
     cookie.Value    = TranslateUtils.EncryptStringBySecretKey(cookie.Value);
     cookie.HttpOnly = true;//防止通过js获取到cookie
     if (HttpContext.Current.Request.Url.Scheme.Equals("https"))
     {
         cookie.Secure = true;//通过https传递cookie
     }
     HttpContext.Current.Response.Cookies.Add(cookie);
 }
Esempio n. 2
0
        private static void SetCookie(HttpCookie cookie, bool isEncrypt)
        {
            cookie.Value    = isEncrypt ? TranslateUtils.EncryptStringBySecretKey(cookie.Value) : cookie.Value;
            cookie.HttpOnly = false;

            if (HttpContext.Current.Request.Url.Scheme.Equals("https"))
            {
                cookie.Secure = true;//通过https传递cookie
            }
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
Esempio n. 3
0
        public static void SetCookie(string name, string value, DateTime expires)
        {
            var myCookie = new HttpCookie(name)
            {
                Value    = TranslateUtils.EncryptStringBySecretKey(value),
                Expires  = expires,
                HttpOnly = true
            };

            //防止通过js获取到cookie
            if (HttpContext.Current.Request.Url.Scheme.Equals("https"))
            {
                myCookie.Secure = true;//通过https传递cookie
            }

            HttpContext.Current.Response.Cookies.Add(myCookie);
        }
Esempio n. 4
0
        public static void UpdateWebConfig(string configPath, bool isProtectData, DatabaseType databaseType, string connectionString, string adminDirectory, string secretKey, bool isNightlyUpdate)
        {
            var doc = new XmlDocument();

            doc.Load(configPath);
            var dirty       = false;
            var appSettings = doc.SelectSingleNode("configuration/appSettings");

            if (appSettings != null)
            {
                foreach (XmlNode setting in appSettings)
                {
                    if (setting.Name == "add")
                    {
                        var attrKey = setting.Attributes?["key"];
                        if (attrKey != null)
                        {
                            if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(IsProtectData)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = isProtectData.ToString();
                                    dirty           = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(DatabaseType)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = databaseType.Value;
                                    if (isProtectData)
                                    {
                                        attrValue.Value = TranslateUtils.EncryptStringBySecretKey(attrValue.Value, secretKey);
                                    }
                                    dirty = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(ConnectionString)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = connectionString;
                                    if (isProtectData)
                                    {
                                        attrValue.Value = TranslateUtils.EncryptStringBySecretKey(attrValue.Value, secretKey);
                                    }
                                    dirty = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(AdminDirectory)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = adminDirectory;
                                    dirty           = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(SecretKey)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = secretKey;
                                    dirty           = true;
                                }
                            }
                            else if (StringUtils.EqualsIgnoreCase(attrKey.Value, nameof(IsNightlyUpdate)))
                            {
                                var attrValue = setting.Attributes["value"];
                                if (attrValue != null)
                                {
                                    attrValue.Value = isNightlyUpdate.ToString();
                                    dirty           = true;
                                }
                            }
                        }
                    }
                }
            }

            if (dirty)
            {
                var writer = new XmlTextWriter(configPath, Encoding.UTF8)
                {
                    Formatting = Formatting.Indented
                };
                doc.Save(writer);
                writer.Flush();
                writer.Close();
            }

            IsProtectData    = isProtectData;
            DatabaseType     = databaseType;
            ConnectionString = connectionString;
        }
Esempio n. 5
0
 public static string GetLoadingUrl(string url)
 {
     return(GetAdminDirectoryUrl($"loading.aspx?redirectUrl={TranslateUtils.EncryptStringBySecretKey(url)}"));
 }
Esempio n. 6
0
 public static void RedirectToErrorPage(string message)
 {
     Redirect(GetAdminDirectoryUrl($"error.aspx?message={TranslateUtils.EncryptStringBySecretKey(message)}"));
 }