Solved

How to block specific website through vb.net web application

Posted on 2013-06-27
2
1,205 Views
Last Modified: 2013-07-09
Hi,

How to block a website in vb.net web application without using a localhost ip (127.0.0.1) & proxy server ip address.

Requirement is when am running my application, specific site should get blocked  while the application is in running status. Application shouldn't communicate with that specific website.

The code given below doesn't works for me. When running this code it's hitting the specific site.

JavaScript
----------------------
In this JavaScript sample am just creating one function and calling this function from another function.
----------------------

<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();
    }

function Open() {

    BlockUrl();

}


Vb.Net
-------------------
In this vb.net sample am just blocking in Page_Load method itself. But i just want to block site, creating one method and calling that method from another.    
-------------------
 
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO

Namespace Sample1

    Public Partial Class _Default
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(sender As Object, e As EventArgs)

            Dim path As [String] = "C:\Windows\System32\drivers\etc\hosts"
            Dim sw As New StreamWriter(path, True)
            Dim sitetoblock As [String] = vbLf & " 127.0.0.1 xyz.com"
            sw.Write(sitetoblock)
            sw.Close()

        End Sub
    End Class
End Namespace

Pls let me know is there any other way to blocking a website using vb.net web application.
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39280596
inside Page_Load() use Me.Request.UserHostAddress to detect the blocked site.
once u did, use Server.Transfer or Response.Redirect, to navigate the user to other page.
an alternative is to handle Application.BeginRequest, detect site ip and call Response.End.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 39280740
>Pls let me know is there any other way to blocking a website using vb.net web application.

Are we talking about blocking ANOTHER website while user is visiting your website? I hope there is no way of doing this :-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question