Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Aug 10, 2023 9:02 pm

Hi, please doublecheck this thread we have here. We don't want to validate external addresses and decide are they valid/working or not, but we want option to blacklist and/or whitelist as you described in post from Aug 05, 2022 (year ago).

If I understand correct, this could be some config of spire lib side, and can provide option to allow communication ONLY to addresses that are OK - by matching to white/black list logic.

bradjen
 
Posts: 29
Joined: Thu Jul 25, 2019 6:07 am

Fri Aug 11, 2023 9:25 am

Hello bradjen,

Thanks for your message.
As for the blacklist and/or whitelist option, our Dev team did more reviews and confirmed that we can implement it as a new interface. However, they are currently making some major adjustments for product internal code, the implementation of this new interface will need to wait for the internal adjustments to be completed. It may take some time to provide your the hotfix version. Anyway, once its' version is available, we will let you know asap.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Wed Sep 27, 2023 10:43 am

Hi,

do you have any updates/progress on this one?

Kind regards,
br.

bradjen
 
Posts: 29
Joined: Thu Jul 25, 2019 6:07 am

Thu Sep 28, 2023 10:15 am

Hello,

Thanks for your patience.
We just released Spire.Office Platinum(Hotfix) Version:8.9.3, it supports the download event and the blacklist. You can use the latest version and refer to the following sample code to test. If there is any other issues, just feel free to write back.
Code: Select all
           static void Main(string[] args)
            {
                Document doc = new Document();
              doc.HtmlUrlLoadEvent += MyDownloadEvent;
             doc.LoadFromFile(@"test.docx");
             doc.SaveToFile(@"test.pdf");
            }
            private static void MyDownloadEvent(object sender, Spire.Doc.Document.HtmlUrlLoadEventArgs args)
            {
                List<string> blacklist = new List<string>
               { "http://google.com", }
                ;

                using (WebClient webClient = new WebClient())
                {
                    webClient.Credentials = CredentialCache.DefaultCredentials;
                    webClient.Headers.Set("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0");
                    if (!IsWebsiteBlocked(args.Url, blacklist))

                    { args.DataBytes = webClient.DownloadData(args.Url); }
                }
            }
            private static bool IsWebsiteBlocked(string website, List<string> blacklist)
            {
                foreach (string blockedSite in blacklist)
                {
                    if (website.StartsWith(blockedSite, StringComparison.OrdinalIgnoreCase))

                    { return true; }
                }
                return false;
            }

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Mon Oct 30, 2023 8:39 am

This is great! We'll give it a test run.

Can you also add whitelist as we already discussed.

bradjen
 
Posts: 29
Joined: Thu Jul 25, 2019 6:07 am

Tue Oct 31, 2023 5:42 am

Hello,

Yes, the whitelist is also the same, such as the following settings, you can define which url can be accessed.
Code: Select all
            Document doc = new Document();
            doc.HtmlUrlLoadEvent += MyDownloadEvent;
            doc.LoadFromFile(@"test.docx");
            doc.SaveToFile(@"out.pdf",FileFormat.PDF);
        }
        private static void MyDownloadEvent(object sender, Spire.Doc.Document.HtmlUrlLoadEventArgs args)
        {
            List<string> whitelist = new List<string>
            { "http://www.e-iceblue.com/downloads/Images/Custom_DPI.jpg"};

            using (WebClient webClient = new WebClient())
            {
                webClient.Credentials = CredentialCache.DefaultCredentials;
                webClient.Headers.Set("user-agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0");
                if (IsWebsiteBlocked(args.Url, whitelist))

                { args.DataBytes = webClient.DownloadData(args.Url); }
            }
        }
        private static bool IsWebsiteBlocked(string website, List<string> whitelist)
        {
            foreach (string blockedSite in whitelist)
            {
                if (website.StartsWith(blockedSite, StringComparison.OrdinalIgnoreCase))

                { return true; }
            }
            return false;
        }

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1536
Joined: Wed Apr 25, 2018 3:20 am

Fri Nov 17, 2023 7:27 am

Thank you!

bradjen
 
Posts: 29
Joined: Thu Jul 25, 2019 6:07 am

Return to Spire.Doc