Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Get proxy, address, credentials and the default credentials associated with the proxy server using “Web Proxy” class in vb and C# .net.

Author: Maliha Atteeq
Download Source Code : 1063_webappz.zip

In this simple article you will how can we get the proxy, address, credentials and the default credentials associated with the proxy server using “Web Proxy” class in vb and C# .net.

 Web proxy:

Proxies are store-and-forward caches. When you configure your web browser to use a proxy, it never connects to the URL. Instead, it always connects to the proxy server, and asks it to get the URL for you. Proxies can be used as a sort of firewall, because it isolates you from connecting to the Internet. A proxy server receives a request for an Internet service (such as a Web page request) from a user. If it passes filtering requirements, the proxy server, assuming it is also a cache server, looks in its local cache of previously downloaded Web pages. If it finds the page, it returns it to the user without needing to forward the request to the Internet. If the page is not in the cache, the proxy server, acting as a client on behalf of the user, uses one of its own IP addresses to request the page from the server out on the Internet. When the page is returned, the proxy server relates it to the original request and forwards it on to the user. To the user, the proxy server is invisible; all Internet requests and returned responses appear to be directly with the addressed Internet server. (The proxy is not quite invisible; its IP address has to be specified as a configuration option to the browser or other protocol program.)

To get proxy:

In order to get proxy of the server, system.net.webproxy class provides us a function named as getProxy(). This function takes one argument as a parameter of class Uri. The return type of this function is also an Uri class. It returns the proxy of the server in the object of the Uri class.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getProxy_Click(object sender, EventArgs e)

        {

            System.Uri ob;

            System.Uri dest = new Uri("http://TestUrl");

            ob=obj.GetProxy(dest);

            MessageBox.Show("the proxy is " + Convert.ToString(ob));

        }

VB:

Private Sub btn_getProxy_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim ob As System.Uri

    Dim dest As System.Uri = New Uri("http://TestUrl")

    ob = obj.GetProxy(dest)

    MessageBox.Show("the proxy is " & Convert.ToString(ob))

End Sub

To get address:

In order to get address of the server, system.net.webproxy class provides us a property named as Address. The return type of this property is the object of an Uri class. It returns the address of the server in the object of the Uri class.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getAddrs_Click(object sender, EventArgs e)

        {

            System.Uri ob;

            ob=obj.Address;

            MessageBox.Show("the address is "+Convert.ToString(ob));

        }

VB:

Private Sub btn_getAddrs_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim ob As System.Uri

    ob = obj.Address

    MessageBox.Show("the address is " & Convert.ToString(ob))

End Sub

To get credentials:

In order to get the credentials of the server, system.net.webproxy class provides us a property named as Credentials. The return type of this property is the object of System.Net.ICredentials. It returns the credentials in this object it is submit for authentication of the server.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getCredentials_Click(object sender, EventArgs e)

        {

            System.Net.ICredentials ob;

            ob=obj.Credentials;

            if (ob == null)

            {

                MessageBox.Show("no credentials is set");

            }

            else

            {

                MessageBox.Show("the credentials is " + Convert.ToString(ob));

            }

        }

VB:

Private Sub btn_getCredentials_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim ob As System.Net.ICredentials

    ob = obj.Credentials

    If ob Is Nothing Then

        MessageBox.Show("no credentials is set")

    Else

        MessageBox.Show("the credentials is " & Convert.ToString(ob))

    End If

End Sub

To check credentials:

In order to check the credentials of the server, system.net.webproxy class provides us a property named as UseDefaultCredentials. The return type of this property is Boolean. It returns true if the credentials is the default one otherwise it will return false.

To demonstrate make a new window application. Drag one button on the form and write the following code:

C#:

private void btn_getDeafultcred_Click(object sender, EventArgs e)

        {

            bool ob;

            ob=obj.UseDefaultCredentials;

            if (ob == true)

            {

                MessageBox.Show("the credential is the default one");

            }

            else

            {

                MessageBox.Show("the credential is not the default one");

            }

        }

VB:

Private Sub btn_getDeafultcred_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim ob As Boolean

    ob = obj.UseDefaultCredentials

    If ob = True Then

        MessageBox.Show("the credential is the default one")

    Else

        MessageBox.Show("the credential is not the default one")

    End If

End Sub

Now write the following code on FORM LOAD event:

C#:

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP APPLICATION";

        }

VB:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

   Me.Text = "DEVASP APPLICATION"

End Sub

This simple article tells how we can get the proxy, address, credentials and the default credentials associated with the proxy server using “Web Proxy” class in vb and C #.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get height, width, frame count and horizontal - vertical resolution of image in VB.net - C#.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net