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 – Set Cache policy – Impersonation level and authenticate header using HttpWebRequest class C#.net – vb.net.

Author: Shehzad Hemani
Download Source Code : 1000_HtmlDocument.zip

In this simple article you will learn that how we can get or set cache policy, impression level and authenticate header for request using HttpWebRequest class C#.net – vb.net.

 For all these operations make object of HttpWebRequest class as discussed in one of my previous articles and also in source file attached with this article.

Cache Policy:

To get/set the cache policy associated with current request we have a property of HttpWebRequest class named CachePolicy. This property takes and returns object of class System.Net.Cache.RequestCachePolicy.

To demonstrate make a window application. Drag one text box and one button on form.

C#

private void btn_cachepolicy_Click(object sender, EventArgs e)

        {

            if (count != 0)

            {

                System.Net.Cache.RequestCachePolicy pl = myWebRequest.CachePolicy;

                string str = pl.ToString();

                MessageBox.Show(str);

            }

            else

                MessageBox.Show("FRIRST MAKE request");

        }

VB

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

        If count <> 0 Then

            Dim pl As System.Net.Cache.RequestCachePolicy = myWebRequest.CachePolicy

            Dim str As String = pl.ToString()

            MessageBox.Show(str)

        Else

            MessageBox.Show("FRIRST MAKE request")

        End If

    End Sub

This is simple code to get the cache policy for the current request.

Impersonation Level:

To get/set the Impersonation level associated with current request we have a property of HttpWebRequest class named ImpersonationLevel. This property takes and returns object of ystem.Security.Principal.TokenImpersonationLevel class.

To demonstrate make a window application. Drag one text box and one button on form.

C#

private void btn_imp_Click(object sender, EventArgs e)

        {

            if (count != 0)

            {

                System.Security.Principal.TokenImpersonationLevel tl = myWebRequest.ImpersonationLevel;

                string str = tl.ToString();

                MessageBox.Show(str);

            }

            else

                MessageBox.Show("FRIRST MAKE request");

        }

VB

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

        If count <> 0 Then

            Dim tl As System.Security.Principal.TokenImpersonationLevel = myWebRequest.ImpersonationLevel

            Dim str As String = tl.ToString()

            MessageBox.Show(str)

        Else

            MessageBox.Show("FRIRST MAKE request")

        End If

    End Sub

This is simple code to get/set Impersonation Level for the current request.

Authentication Header:

To get/set that the authenticate header should be sent with the current request or not we have a property of HttpWebRequest class named PreAuthenticate. This property takes and returns Boolean value.

To demonstrate make a window application. Drag one text box and one button on form.

C#

private void btn_authentication_Click(object sender, EventArgs e)

        {

            if (count != 0)

            {

                bool b = myWebRequest.PreAuthenticate;

                string str = b.ToString();

                MessageBox.Show(str);

            }

            else

                MessageBox.Show("FRIRST MAKE request");

        }

VB

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

        If count <> 0 Then

            Dim b As Boolean = myWebRequest.PreAuthenticate

            Dim str As String = b.ToString()

            MessageBox.Show(str)

        Else

            MessageBox.Show("FRIRST MAKE request")

        End If

    End Sub

This is simple code to get/set that authenticate header should be sent or not for the current request.

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 or set cache policy, impression level and authenticate header for request using HttpWebRequest class C#.net – vb.net.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Get cookies – response stream and protocol version for response from server using HttpWebResponse class C#.net – vb.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net