如何使用 DotNet 以编程方式阻止网站 [英] How to block a website programatically using DotNet

查看:19
本文介绍了如何使用 DotNet 以编程方式阻止网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Windows 应用程序,以使用 DotNet Windows 编程阻止来自计算机的网站.我发现一些结果可以阻止 url,但不能阻止网站.那是我必须阻止完整的网站而不是单个网址.

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 is I have to block complete website not a single url.

谁能帮我解决这个问题

谢谢

柴塔尼亚

推荐答案

听起来您想要 System.Uri 类的服务 (http://msdn.microsoft.com/en-us/library/system.uri.aspx).我猜在某个时候您必须根据 URI 决定是允许还是禁止请求,在这种情况下,您将需要类似于以下的逻辑:

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:

  • 如果您检查主机是否等于www.google.co.uk",那么这仍然意味着其他子域(例如www3.google.co.uk")不会被阻止.
  • 如果您检查主机是否包含google.co.uk",那么您可能会阻止其他人的子域包含(出于愚蠢的原因)其他人的网址,例如google.co.uk.MyDomain.co.uk"这仍然是MyDomain.co.uk"域下的有效子域(如果是愚蠢的).

这篇关于如何使用 DotNet 以编程方式阻止网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆