Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url 如何对URI进行编码以安全地存储在TableServiceEntity的RowKey中?_Url_Uri_Azure Storage_Azure Table Storage - Fatal编程技术网

Url 如何对URI进行编码以安全地存储在TableServiceEntity的RowKey中?

Url 如何对URI进行编码以安全地存储在TableServiceEntity的RowKey中?,url,uri,azure-storage,azure-table-storage,Url,Uri,Azure Storage,Azure Table Storage,我非常非常希望在Azure表存储中存储URI作为行键值。根据,行键不能包含URI中常见的字符(/,\,#,?) 解决方案似乎很简单:只需对URI进行编码。但这不起作用。无论出于何种原因,都可以插入包含序列%2f(正斜杠的编码值)的任何值,但即使“%2f”不包含任何禁止的字符,也不能查询 好的,那么base64编码呢?不。它偶尔会产生正斜杠字符,这是不允许的 那么,有没有一种编码字符串(URI)的方法可以可靠地存储为Azure表中的RowKey呢?最好是,但不一定是人类可读的东西。一些可能性: 使

我非常非常希望在Azure表存储中存储URI作为行键值。根据,行键不能包含URI中常见的字符(/,\,#,?)

解决方案似乎很简单:只需对URI进行编码。但这不起作用。无论出于何种原因,都可以插入包含序列%2f(正斜杠的编码值)的任何值,但即使“%2f”不包含任何禁止的字符,也不能查询

好的,那么base64编码呢?不。它偶尔会产生正斜杠字符,这是不允许的

那么,有没有一种编码字符串(URI)的方法可以可靠地存储为Azure表中的RowKey呢?最好是,但不一定是人类可读的东西。

一些可能性:

  • 使用特定的编码(如UTF-8)转换字节,然后将字节编码为十六进制。把它当作钥匙。但是,有些URI可能非常长,而且密钥甚至更长,因此您可能会遇到RowKey的最大长度
  • 散列URI(例如,使用MD5)。十六进制编码这些字节,并使用它们作为键。请注意,存在冲突的可能性,但您的PartitionKey可能会消除这种可能性。因为散列是恒定长度的,所以最大行键长度不应该有问题
    我肯定还有其他想法,我很想听听

    离题但相关:我正在动态创建表,如果您需要,我的代码可能会对您有所帮助,尽管表和PK/RK的规则非常不同。“^[A-Za-z][A-Za-z0-9]{2,62}$”

    也许你可以用它来启发你自己的解决方案

    解码字符串

            string edit1 = host
                .Replace("qqu", "_")
                .Replace("qqh", "-")
                .Replace("qqp", ".")
    
                // NOTE: qqn is reserved leading sequence
    
                .Replace("qqt", "qqu")
                .Replace("qqo", "qqp")
                .Replace("qqg", "qqh")
                ;
    
            if (edit1.StartsWith("qqn"))
            {
                edit1 = edit1.Substring(3, edit1.Length);
            }
            if (edit1.StartsWith("qq"))
            {
                edit1 = edit1.Substring(2, edit1.Length);
            }
    
                string edit1 = this.originalName.ToLower().Trim()
                    .Replace("qqu", "qqt")
                    .Replace("qqp", "qqo")
                    .Replace("qqh", "qqg")
    
                    // NOTE: qqn is reserved leading sequence
    
                    .Replace("_", "qqu")
                    .Replace("-", "qqh")
                    .Replace(".", "qqp");
    
                string test = "qq";
                if (edit1.StartsWith(test))
                    return test + "n" + edit1;
    
                test = "0";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "1";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "2";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "3";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "4";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "5";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "6";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "7";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "8";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "9";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "0";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
    方法对字符串进行编码

            string edit1 = host
                .Replace("qqu", "_")
                .Replace("qqh", "-")
                .Replace("qqp", ".")
    
                // NOTE: qqn is reserved leading sequence
    
                .Replace("qqt", "qqu")
                .Replace("qqo", "qqp")
                .Replace("qqg", "qqh")
                ;
    
            if (edit1.StartsWith("qqn"))
            {
                edit1 = edit1.Substring(3, edit1.Length);
            }
            if (edit1.StartsWith("qq"))
            {
                edit1 = edit1.Substring(2, edit1.Length);
            }
    
                string edit1 = this.originalName.ToLower().Trim()
                    .Replace("qqu", "qqt")
                    .Replace("qqp", "qqo")
                    .Replace("qqh", "qqg")
    
                    // NOTE: qqn is reserved leading sequence
    
                    .Replace("_", "qqu")
                    .Replace("-", "qqh")
                    .Replace(".", "qqp");
    
                string test = "qq";
                if (edit1.StartsWith(test))
                    return test + "n" + edit1;
    
                test = "0";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "1";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "2";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "3";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "4";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "5";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "6";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "7";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "8";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "9";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    
                test = "0";
                if (edit1.StartsWith(test))
                    return "qq" + edit1;
    

    将URL中所有非法的行键字符(\,/,?)替换为URL中非法的字符(例如,%)

    在使用base64编码后将/替换为uu应该可以工作。

    获得此建议。此建议无效,因为不允许使用某些(未记录的)字符序列。一个已知序列是%2f。这允许使用查询启动