Lab 1 - Using Basic HTML and ASP Tags - CertifiedNetworks.com

bubblemessengerΑσφάλεια

5 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

230 εμφανίσεις

Lab

2A: An ASP.NET
Redirection

1

Lab 2A


ASP.NET
Redirection


ASP.NET encapsulates and makes the job of controlling the browser more intuitive. Among other things,
ASP.NET exposes objects with various methods and properties that control the header and the body
sections of the HTTP respo
nse.


In this lab, you will
use Visual Studio to
create a simple ASP.NET page that redirects to another website of
your choice.
The ASP.NET code is really controlling the HTTP header, sending a standard redirect to the
client.




Exercise 1: Creating the
Project


To create a new project:


1. Open Visual Studio, and choose file/new project

2. Select Visual Basic under type, and ASP.NET Web Application under template.

3. For the location box, remove the default of WebApplication1, and type in Redirector




4. Drag a button and a dropdownlist onto your form

5.

To bring yourself to the Page_Load event handler, double click an unused area on the form

6.

Type in the following code in the subroutine:


Private

Sub

Page_Load(
ByVal

sender
As

System.Object,
ByVal

e
A
s

System.EventArgs)
Handles

MyBase
.Load


'Put user code to initialize the page here


If

Not

IsPostBack
Then


Button1.Text = "OK"


DropDownList1.Items.Add("http://www.disney.com")


DropDownList1.Items.Add("http://www.worldcom.
com")


DropDownList1.Items.Add("http://www.cisco.com")

2

Lab 2A: An ASP.NET Example


End

If


End

Sub


The line “If Not IsPostBack” tests to make sure this is the first time browsing the page. In other words,
IsPostBack will be true after the initial visit to the page. Mos
t ASP.NET code will live in the Page_Load
subroutine, and quite often involves testing IsPostBack


7.

Test your page…it s
hould look something like this:


If you click the OK button, you should see that the page is posted to itself by default. Next we will
add
code to the page to cause a redirection to occur.


8. Double click the button in Visual Studio to create a Button1_click event, and code it as follows:


Private

Sub

Button1_Click(
ByVal

sender
As

System.Object,
ByVal

e
As

System.EventArgs)
Handles

Butt
on1.Click


Response.Redirect(DropDownList1.SelectedItem.Text)

End

Sub


9. Test the functionality of the page
. Th
e button click e
vent handler should
send the
redirect

header
to your
browser. View the traffic in Network Monitor, and try to identify the
redirect response.


For a copy of the completed exercise, see:
\
\
INSTRUCTOR
\
PUBLIC

or the class website at
http://www.certifiednetworks.com/classes/aspnetclass