Ejemplo n.º 1
0
        public static string SubString(string demand, int length, string substitute)
        {
            demand = DataSecurity.HtmlDecode(demand);
            if (Encoding.Default.GetBytes(demand).Length <= length)
            {
                return(demand);
            }
            ASCIIEncoding encoding = new ASCIIEncoding();

            length -= Encoding.Default.GetBytes(substitute).Length;
            int           num     = 0;
            StringBuilder builder = new StringBuilder();

            byte[] bytes = encoding.GetBytes(demand);
            for (int i = 0; i < bytes.Length; i++)
            {
                if (bytes[i] == 0x3f)
                {
                    num += 2;
                }
                else
                {
                    num++;
                }
                if (num > length)
                {
                    break;
                }
                builder.Append(demand.Substring(i, 1));
            }
            builder.Append(substitute);
            return(builder.ToString());
        }
Ejemplo n.º 2
0
 public static string ConvertAbsolutePath(string virtualPath, string weburl)
 {
     if (string.IsNullOrEmpty(weburl))
     {
         return(string.Empty);
     }
     if (!weburl.Contains("://") && !weburl.StartsWith("/", StringComparison.Ordinal))
     {
         return(DataSecurity.UrlEncode(virtualPath + weburl));
     }
     return(DataSecurity.UrlEncode(weburl));
 }
Ejemplo n.º 3
0
 public static string ConvertAbsolutePath(string virtualPath, string weburl, bool isSEncode)
 {
     if (!isSEncode)
     {
         return(ConvertAbsolutePath(virtualPath, weburl));
     }
     if (string.IsNullOrEmpty(weburl))
     {
         return(string.Empty);
     }
     if (!weburl.Contains("://") && !weburl.StartsWith("/", StringComparison.Ordinal))
     {
         return(virtualPath + DataSecurity.UrlEncode(weburl, true));
     }
     return(DataSecurity.UrlEncode(weburl, true).Replace("%3a%2f%2f", "://").Replace("%2f", "/"));
 }