How to block a website programatically using DotNet

后端 未结 2 2001
生来不讨喜
生来不讨喜 2020-12-10 23:35

I am developing a windows application to block the websites from a computer using DotNet windows programming.I found some results to block an url but not for a website. That

2条回答
  •  执念已碎
    2020-12-10 23:54

    It sounds like you want the services of the System.Uri class (http://msdn.microsoft.com/en-us/library/system.uri.aspx). I'm guessing that at some point you have to decide whether or not you are going to allow or disallow a request based on the URI, in which case you will want logic similar to the following:

    Uri uri = new Uri("http://www.google.co.uk/somepage.html");
    if (uri.Host.ToLower().EndsWith("google.co.uk"))
    {
        // Do something
    }
    

    Experiment with something like that. Things to note are that:

    • If you check to see if the host equals "www.google.co.uk" then this would still mean that other subdomains (e.g. "www3.google.co.uk") wouldnt be blocked.
    • If you check to see if the host contains "google.co.uk" then you risk blocking others whose subdomain contains (for stupid reasons) someone elses url, for example "google.co.uk.MyDomain.co.uk" which is still a valid (if stupid) subdomain under the "MyDomain.co.uk" domain.

提交回复
热议问题