protected void btnAuthenticate_Click(object sender, EventArgs e)
    {
        string[] urls = txtUrls.Text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
        txtUrls.Text = "";

        foreach (string url in urls)
        {
            string urlWithoutHash = URLHelper.RemoveParameterFromUrl(url, "hash");
            string newUrl         = HttpUtility.UrlDecode(urlWithoutHash);
            string query          = URLHelper.GetQuery(newUrl).TrimStart('?');

            int index = newUrl.IndexOfCSafe("/rest");
            if (index >= 0)
            {
                // Extract the domain
                string domain = URLHelper.GetDomain(newUrl);

                // Separate the query
                newUrl = URLHelper.RemoveQuery(newUrl.Substring(index));

                // Rewrite the URL to physical URL
                string[] rewritten = BaseRESTService.RewriteRESTUrl(newUrl, query, domain, "GET");
                newUrl = rewritten[0].TrimStart('~') + "?" + rewritten[1];

                // Get the hash from real URL
                txtUrls.Text += URLHelper.AddParameterToUrl(urlWithoutHash, "hash", RESTService.GetHashForURL(newUrl, domain)) + Environment.NewLine;
            }
            else
            {
                txtUrls.Text += url + Environment.NewLine;
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Generate the secure URL (original URL with hash)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void HashGenerateSecureUrl(object sender, ObjectEventArgs e)
    {
        var url           = e.Object.GetStringValue("HashUrl", string.Empty);
        var hashSecureUrl = "";

        var urlWithoutHash = URLHelper.RemoveParameterFromUrl(url, "hash");
        var newUrl         = HttpUtility.UrlDecode(urlWithoutHash);
        var query          = URLHelper.GetQuery(newUrl).TrimStart('?');

        int index = newUrl.IndexOfCSafe("/rest", true);

        if (index >= 0)
        {
            var domain = URLHelper.GetDomain(newUrl);
            newUrl = URLHelper.RemoveQuery(newUrl.Substring(index));

            var rewritten = BaseRESTService.RewriteRESTUrl(newUrl, query, domain, "GET");
            newUrl = rewritten[0].TrimStart('~') + "?" + rewritten[1];

            hashSecureUrl += URLHelper.AddParameterToUrl(urlWithoutHash, "hash", RESTService.GetHashForURL(newUrl, domain)) + Environment.NewLine;
            e.Object.SetValue("HashSecureUrl", hashSecureUrl);
        }
    }