P. 1
ASP Net

ASP Net

5.0

|Views: 2,821|Likes:
Published by Abdulraheman

More info:

Published by: Abdulraheman on Jun 04, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

12/16/2012

pdf

text

original

200

ASP.NET

REDIRECT USING RESPONSE.REDIRECT

103617-6 Ch09.F 9/26/01 9:44 AM Page 200

° Create a switch
statement using the
string variable.

· Add a case for each of
the options that redirects
to the appropriate page.

‚ Save the file and request
from the Web server.

— Copy the files
FewerGoals.aspx,
MoreGoals.aspx,
SameGoals.aspx, and
ErrorGoals.aspx from
the CD-ROM to your working
directory.

I The page with suggestions
appears.

± Click and select a
suggestion.

¡ Click the Submit button.

I You are redirected to a
page according to the option
you have selected.

You can create a page that accepts a page name from
theQueryStringandredirectstheusertothatpage.

201

USING ASP.NET COMPONENTS 9

TYPE THIS:

<% @ PAGE LANGUAGE="C#" Buffer="True"%>

<%
if (Request.QueryString["pageName"] != null) {
string stringPageName = Request.QueryString["pageName"]
.ToString();
Response.Redirect(stringPageName);

}
else {

Response.Redirect(Request.Url.ToString() +
"?pageName=ie.aspx");

}

%>

RESULT:

A request to this page with
aquery string equal to

pageName=request.aspx

will redirect the request to
the request.aspxpage.
Ifthe page is not specified,
then you are redirected to

ie.aspx.

103617-6 Ch09.F 9/26/01 9:44 AM Page 201

⁄ Open a new document in
your text editor.

¤ Add the page directive,
set the language for the page
to C#, and buffer the page.

‹ Add a pair of script
delimiters.

› Create a new variable of type

HttpBrowserCapabilities

and initialize the variable by
using the Request.Browser
property.

ˇ Create a new variable
of type string and read
the Web browser type
property into the string.

You can use the HttpBrowserCapabilities

class to find out the properties of a user’s Web
browser.You can then use this information in
your code to determine what the proper response to
your client should be.Perhaps you might redirect the
user to another page based on the browser type.You
could also use the HttpBrowserCapabilities
class for information to do custom logging that tracks
what types of browsers are accessing your site.

Some sites that you build with depend on browser
capabilities for making decisions on what is sent to
the user of the site.For example,you might have a
few pages on your site that can be enhanced with
ActiveX controls.Before sending the ActiveX control

in the response,you want to check to see whether
the users support ActiveX controls.If they do not,you
can redirect them to a page that is implemented
without an ActiveX control.

To use the HttpBrowserCapabilities
class,you need to create a variable of type
HttpBrowserCapabilities.With this variable,
you can use the Request.Browserproperty to
return all of the information about the user’s Web
browser.After you have this information,you can use
the property of interest.For example,the Browser
property is used to determine where to send the user.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->