nager / Nager.PublicSuffix

.NET public suffix domain parser
MIT License
155 stars 22 forks source link

Is it possible to not use the write permission on Windows when using the package? #58

Closed sinapy closed 1 year ago

sinapy commented 1 year ago

When using the package, we got this error:

title description
Message "Access to the path 'C:\Windows\TEMP\publicsuffixcache.dat' is denied."
Exception type System.UnauthorizedAccessException
Failed method Nager.PublicSuffix.FileCachePrivider + d_4.MoveNext

This happened because we don't allow our application to have write access to filesystems.

From what I investigated, it seems like the cache object is always being created when TldWeb object is passed to the constructor of DomainParser.

Is there any other way to use the DomainParser without creating a file for cache or not use cache at all?

Currently we are using this:

//cache data for 10 hours
var cacheProvider = new FileCacheProvider(cacheTimeToLive: new TimeSpan(10, 0, 0));
var webTldRuleProvider = new WebTldRuleProvider(cacheProvider: cacheProvider);

var domainParser = new DomainParser(WebTldRuleProvider);

var isValid = webTldRuleProvider.CacheProvider.IsCacheValid();
if (!isValid)
{
    webTldRuleProvider.BuildAsync().GetAwaiter().GetResult(); //Reload data
}

var domainInfo = domainParser.Parse(post.Url);
}

Our goal is to get "youtube" from "www.youtube.com/somevalue", or "wikipedia" from "www.wikipedia.org/somevalue", for the urls in our objects.

tinohager commented 1 year ago

Hi

You can implement an own ICacheProvider https://github.com/nager/Nager.PublicSuffix/blob/8ad4fe4240624398543b78b35c6c0fef1e5f3903/src/Nager.PublicSuffix/WebTldRuleProvider.cs#LL26C105-L26C105

sinapy commented 1 year ago

Thanks @tinohager , I think this does solve the issue.