如何阻止来自vb.net Web应用程序的网站请求/响应 [英] How to block request/response to a website from vb.net web application

查看:103
本文介绍了如何阻止来自vb.net Web应用程序的网站请求/响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要阻止我的vb.net网络应用程序中的网站。要求是在运行我的应用程序时我需要通过我的应用程序阻止对特定网站的请求/响应。



我尝试了很多方法,但代码下面给出的并没有给出确切的解决方案。



1)



Hi all,

I need to block a website from my vb.net web application. Requirement is when am running my application I need to block request/response to a specific website through my application.

I've tried in so many ways, but the codes given below doesn't gives me the exact solution.

1)

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        path = "C:\Windows\System32\drivers\etc\hosts"
        sw = New StreamWriter(path, True)
        Dim sitetoblock As String = "\n 127.0.0.1 xyz.com"
        sw.Write(sitetoblock)
        sw.Close()
        Response.Write("<script>alert('Site Blocked'); </script>")
    End Sub





2)



2)

<script type="text/javascript" language="javascript">
     function BlockUrl() 
      {

            var path = "C:\Windows\System32\drivers\etc\hosts";
            var sw = new StreamWriter(path, True);
            var sitetoblock = vbLf & " 127.0.0.1 xyz.com";
            sw.Write(sitetoblock);
            sw.Close();
      }





请为此提供一些解决方案...



谢谢和问候,

Ashok



Please give some solutions for this...

Thanks and regards,
Ashok

推荐答案

这个小技巧不会为你做任何事情。首先,它只阻止目标站点的名称解析,而不是阻止流量的传输。



为什么不工作?因为机器已经将DNS名称解析为IP并在DnsCache中缓存。每次修改主机文件时都需要清除缓存。



但是,这只会阻止您将名称解析为IP地址。如果用户输入IP地址代替URL中的DNS名称,那么您的小块将无法正常工作。



阻止传输的唯一方法流量是写代理服务器!我希望你知道TCP / IP客户端/服务器通信,因为你将在这个项目中游泳。
This little technique isn't going to do anything for you. First, it only blocks the name resolution of the target site, not block the transmission of traffic.

Why doesn't it work?? Because the machine already had the DNS name resolved to an IP and cached in the DnsCache. You'd need to clear the cache every time you modify the hosts file.

BUT, this ONLY stops your from resolving the name to an IP address. If the user types in the IP address in place of the DNS name in the URL, your little block won't work at all.

THe only way to block transmission of traffic is to write a proxy server! I hope you know TCP/IP client/server communication because you're going to be swimming in it in this project.


这篇关于如何阻止来自vb.net Web应用程序的网站请求/响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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