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); }
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); }
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); }
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; }
public static string GetLoadingUrl(string url) { return(GetAdminDirectoryUrl($"loading.aspx?redirectUrl={TranslateUtils.EncryptStringBySecretKey(url)}")); }
public static void RedirectToErrorPage(string message) { Redirect(GetAdminDirectoryUrl($"error.aspx?message={TranslateUtils.EncryptStringBySecretKey(message)}")); }