private string GetHtmlVersionReplaced(string HtmlSrc, string HtmlDest) { Dictionary <string, string> dicUrlAndVer = new Dictionary <string, string>(); Regex rDest = new Regex(_PatternUrl, CRegex.Options.Compiled_Multiline_IgnoreCase_IgnorePatternWhitespace); foreach (Match m in rDest.Matches(HtmlDest)) { string Url = m.Groups["Url"].Value; CQueryString qs = new CQueryString(Url); if (string.IsNullOrEmpty(qs["v"])) { continue; } dicUrlAndVer.Add(qs.PathOnly, qs["v"]); } StringBuilder sbHtml = new StringBuilder(); List <string> aUrl = new List <string>(); bool IsFound = false; Regex rSrc = new Regex(_PatternUrl, CRegex.Options.Compiled_Multiline_IgnoreCase_IgnorePatternWhitespace); foreach (CMatchInfo mi in CRegex.GetMatchResult(rSrc, HtmlSrc)) { sbHtml.Append(mi.ValueBeforeMatch); if (mi.Match == null) { break; } string Url = mi.Match.Groups["Url"].Value; CQueryString qs = new CQueryString(Url); string VersionIs; dicUrlAndVer.TryGetValue(qs.PathOnly, out VersionIs); if (string.IsNullOrEmpty(VersionIs)) { sbHtml.Append(mi.Match.Value); } else { IsFound = true; sbHtml.Append(mi.Match.Value.Replace(mi.Match.Groups["Url"].Value, qs.PathOnly + "?v=" + VersionIs)); } } if (!IsFound) { return(""); } return(sbHtml.ToString()); }
/// <summary> /// 현재 페이지 경로 앞에 Full URL을 덧붙인 값을 리턴함. /// 예를 들어 현재 페이지 경로가 "/test.aspx"이면, "http://www.myurl.com/test.aspx"로 변경함. /// </summary> public static string PrefixHttpToCurrentUrl() { HttpRequest Req = HttpContext.Current.Request; string Url = "http://" + Req.ServerVariables["HTTP_HOST"] + Req.ServerVariables["PATH_INFO"]; string Param = Req.ServerVariables["QUERY_STRING"]; string UrlParam = CQueryString.AppendQueryString(Url, Param); return(UrlParam); }
/// <summary> /// 한쪽에서 저장된 쿠키 정보를 다른쪽에서 읽는 작업을 실제로 함. /// </summary> private static void MergeCookie(HttpCookieCollection CookToOverwrite) { HttpCookieCollection CookiesCur = HttpContext.Current.Request.Cookies; HttpCookieCollection CookiesWrite = HttpContext.Current.Response.Cookies; bool IsChanged = false; //현재 쿠키와 이전 쿠키에 일치하는 이름이 있다면 이전 쿠키 값을 덮어씀. for (int i = 0, i2 = CookiesCur.Count; i < i2; i++) { string Key = CookiesCur.GetKey(i); string Value = CookiesCur[i].Value; if (CookToOverwrite[Key] == null) { continue; } if (Value != CookToOverwrite[Key].Value) { CookiesWrite[Key].Value = CookToOverwrite[Key].Value; IsChanged = true; } } //이전 쿠키에서 추가된 값이 있다면 현재 쿠키에 추가함. for (int i = 0, i2 = CookToOverwrite.Count; i < i2; i++) { string Key = CookToOverwrite.GetKey(i); string Value = CookToOverwrite[i].Value; if (CookiesCur[Key] == null) { CookiesWrite.Add(new HttpCookie(Key, Value)); IsChanged = true; } } if (IsChanged) { //클라이언트로 가기 전까지는 변경된 쿠키를 읽을 수 없으므로 //현재 페이지를 다시 호출함. HttpRequest Req = HttpContext.Current.Request; HttpResponse Resp = HttpContext.Current.Response; string UrlParam = CQueryString.AppendQueryString(Req.ServerVariables["PATH_INFO"], Req.ServerVariables["QUERY_STRING"]); Resp.Redirect(UrlParam, true); } }
private List <Tuple <string, string, CFtpInfoSync> > GetPathAndHtmlAndFtpInfoDest(string[] aFullPathReferencingJs, FileInfo fiSrc) { List <Tuple <string, string, CFtpInfoSync> > tpPathAndHtml = new List <Tuple <string, string, CFtpInfoSync> >(); if (aFullPathReferencingJs.Length == 0) { return(tpPathAndHtml); } List <Tuple <string, string, CFtpInfoSync> > tpFullPathReferencingDest = GetFullPathReferencingDest(aFullPathReferencingJs); if (tpFullPathReferencingDest.Count == 0) { return(tpPathAndHtml); } foreach (Tuple <string, string, CFtpInfoSync> kv in tpFullPathReferencingDest) { string FullPathSrc = kv.Item1; string FullPathDest = kv.Item2; CFtpInfoSync FtpInfo = kv.Item3; string Html = ""; if (_DestType == DestTypes.FileSystem) { if (!File.Exists(FullPathDest)) { continue; } Html = CFile.GetTextInFile(FullPathDest); } else if (_DestType == DestTypes.Ftp) { CFtp2 Ftp = new CFtp2(FtpInfo); if (!Ftp.FileExists(FullPathDest)) { continue; } string TmpFullPath = CFile.GetTempFileName(); Ftp.DownloadFile(TmpFullPath, FullPathDest); Html = CFile.GetTextInFile(TmpFullPath); } List <string> aHtmlNew = new List <string>(); string Pattern = string.Format(_PatternUrlSpecific, fiSrc.Name.Replace(".", "\\.")); Regex r = new Regex(Pattern, CRegex.Options.Compiled_Multiline_IgnoreCase_IgnorePatternWhitespace); bool IsFound = false; foreach (CMatchInfo mi in CRegex.GetMatchResult(r, Html)) { aHtmlNew.Add(mi.ValueBeforeMatch); Match m = mi.Match; if (m == null) { break; } string Url = m.Groups["Url"].Value; CQueryString qs = new CQueryString(Url); //Commented because v parameter can be setted to empty when referencing file uploaded alone. //When that situation, v parameter will get value of 1 again. //qs["v"] = (CFindRep.IfNotNumberThen0(qs["v"]) + 1).ToString(); qs["v"] = DateTime.Now.ToString(CConst.Format_yyyyMMddHHmmss); aHtmlNew.Add(m.Value.Replace(m.Groups["Url"].Value, qs.PathAndQuery)); IsFound = true; } if (IsFound) { string HtmlNew = string.Join("", aHtmlNew); tpPathAndHtml.Add(new Tuple <string, string, CFtpInfoSync>(FullPathDest, HtmlNew, FtpInfo)); } } return(tpPathAndHtml); }
public static string AppendQueryString(Uri uri, string QueryString) { return(CQueryString.AppendQueryString(uri.AbsoluteUri, QueryString)); }