public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { List <ValidationResult> errorList = new List <ValidationResult>(); if (IsClosed == 1 && string.IsNullOrWhiteSpace(CloseReason)) { errorList.Add(new ValidationResult("请填写商城关闭原因!", new string[] { "CloseReason" })); } if (CookieDomain != null && (!CookieDomain.Contains(".") || !WebHelper.GetHost().Contains(CookieDomain))) { errorList.Add(new ValidationResult("cookie域不合法!", new string[] { "CookieDomain" })); } //if (!string.IsNullOrWhiteSpace(BanAccessTime)) //{ // string[] timeList = StringHelper.SplitString(BanAccessTime, "\r\n"); // foreach (string time in timeList) // { // string[] startTimeAndEndTime = StringHelper.SplitString(time, "-"); // if (startTimeAndEndTime.Length == 2) // { // foreach (string item in startTimeAndEndTime) // { // string[] hourAndMinute = StringHelper.SplitString(item, ":"); // if (hourAndMinute.Length == 2) // { // if (!CheckTime(hourAndMinute[0], hourAndMinute[1])) // { // errorList.Add(new ValidationResult("时间格式不正确!", new string[] { "BanAccessTime" })); // break; // } // } // else // { // errorList.Add(new ValidationResult("时间格式不正确!", new string[] { "BanAccessTime" })); // break; // } // } // } // else // { // errorList.Add(new ValidationResult("时间格式不正确!", new string[] { "BanAccessTime" })); // break; // } // } //} return(errorList); }
/// <summary> /// 设置Cookie /// </summary> /// <param name="CookieName">Cookie名称</param> /// <param name="CookieValue">Cookie值</param> /// <param name="DateExpires">过期时间</param> /// <param name="Domain">设置Cookie的域名类型</param> /// <param name="Path">Cookie路径,默认为"/",可指定路径(如/test/,/test/temp/)</param> public static void SetCookie(string CookieName, string CookieValue, DateTime DateExpires, CookieDomain Domain = CookieDomain.CurrentDomain, string Path = "/") { var cookie = new HttpCookie(CookieName); cookie.Value = CookieValue; cookie.Expires = DateExpires; if (Domain == CookieDomain.CurrentDomain) { cookie.Domain = HttpContext.Current.Request.Url.Host.ToLower(); } else if (Domain == CookieDomain.TopDomain) { var host = HttpContext.Current.Request.Url.Host.ToLower(); var arr = host.Split('.'); if (arr.Length > 2) { host = "." + arr[arr.Length - 2] + "." + arr[arr.Length - 1]; } cookie.Domain = host; } cookie.Path = Path; HttpContext.Current.Response.Cookies.Add(cookie); }
/// <summary> /// 移除Cookie /// </summary> /// <param name="CookieName">Cookie名称</param> /// <param name="Domain">设置Cookie的域名类型</param> /// <param name="Path">Cookie路径,默认为"/",可指定路径(如/test/,/test/temp/)</param> public static void RemoveCookie(string CookieName, CookieDomain Domain = CookieDomain.CurrentDomain, string Path = "/") { SetCookie(CookieName, "", -99, Domain, Path); }
/// <summary> /// 设置Cookie /// </summary> /// <param name="CookieName">Cookie名称</param> /// <param name="CookieValue">Cookie值</param> /// <param name="DayExpires">过期天数,默认1天</param> /// <param name="Domain">设置Cookie的域名类型</param> /// <param name="Path">Cookie路径,默认为"/",可指定路径(如/test/,/test/temp/)</param> public static void SetCookie(string CookieName, string CookieValue, double DayExpires = 1, CookieDomain Domain = CookieDomain.CurrentDomain, string Path = "/") { SetCookie(CookieName, CookieValue, DateTime.Now.Date.AddDays(DayExpires), Domain, Path); }