How to block a website programatically using DotNet

后端 未结 2 1991
生来不讨喜
生来不讨喜 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.
    0 讨论(0)
  • 2020-12-10 23:56

    Why are you using an application running on the local machine to do this? It doesn't make much sense. This is done through a corporate proxy, generally.

    You may edit the

    c:\windows\system32\drivers\etc\hosts
    

    File to resolve a domain name to '127.0.0.1', instead of what it would normally do, to stop it being visible in that fashion. But it's better to do it properly.

    Please describe what you're trying to do in more detail.

    0 讨论(0)
提交回复
热议问题