473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Correct way to use Response Redirect in .NET

Hello, I have an old asp page that was used to redirect users called
redirect.asp:

<code1>
<%
Option Explicit

If Request.QueryString("url") <> "" Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("www.examplesite.asp")
End If
%>
</code1>
So far I have this:

<code2>
<%@ Page Language="vb" enableviewstate="False"%>
<script runat=server>
Public Sub Page_Load()
Response.Redirect ("http://www.tv.dlpsaleslab.com/default.aspx")
End Sub
</script>
</code2>

My question is how do I use VB.NET to do this.
When I add the above code I am given an error, since I am new to VB,
can someone help advise what is the proper way to set up a
Response.Redirect in the manner as I have done in in code1 using
VB.NET?

Thank you,
Jul 21 '05 #1
8 3160
The need for Response.Redirect is greatly diminished in .NET. Look into
Page.IsPostBack.
"Daniel" <te**********@yahoo.com> wrote in message
news:78**************************@posting.google.c om...
Hello, I have an old asp page that was used to redirect users called
redirect.asp:

<code1>
<%
Option Explicit

If Request.QueryString("url") <> "" Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("www.examplesite.asp")
End If
%>
</code1>
So far I have this:

<code2>
<%@ Page Language="vb" enableviewstate="False"%>
<script runat=server>
Public Sub Page_Load()
Response.Redirect ("http://www.tv.dlpsaleslab.com/default.aspx")
End Sub
</script>
</code2>

My question is how do I use VB.NET to do this.
When I add the above code I am given an error, since I am new to VB,
can someone help advise what is the proper way to set up a
Response.Redirect in the manner as I have done in in code1 using
VB.NET?

Thank you,

Jul 21 '05 #2
So to clarify, how to I use Page.IsPostBack in this manner to accomplish
the same as I have done in the first bit of code?

Any help would be appreciated?

Thanks,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
Here is a brief explanation of how and when to use...

Response.Redirect functions in ASP.NET exactly as it did in ASP
as the intrinsic ASP objects have been carried over to ASP.NET
for backward compatibility.

Using Response.Redirect requires two trips to the server and imposes
performance penalties and should only be used when the three
following circumstances demand its use...

1.) When redirecting to a remote server.
2.) When redirecting to a different website on the same server.
3.) When redirecting to static pages, i.e. from .asp to .htm, .aspx to .htm
or to pages generated by different application servers such as .asp to .php
and .aspx to .php.

Otherwise use the Server.Transfer method or Server.Execute as the
circumstances may require.

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Terry Ashley" <te**********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
So to clarify, how to I use Page.IsPostBack in this manner to accomplish
the same as I have done in the first bit of code?

Any help would be appreciated?

Thanks,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #4
It looks like you were trying to see if the page had ever been loaded before
(if it had, there would be a querystring value). So, in .NET we'd do:

If IsPostBack Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("www.examplesite.asp")
End If

Using Redirect only in circumstances previously posted.

"Terry Ashley" <te**********@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
So to clarify, how to I use Page.IsPostBack in this manner to accomplish
the same as I have done in the first bit of code?

Any help would be appreciated?

Thanks,

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #5
So since i am doing both 2,3 here using Response.Redirect is the right
way to go.

So in fact this seems to work, but as far as using ASP.NET correctly is
this the proper way to format it, if so thank you very much.

<%@ Page Language="vb" enableviewstate="False"%>
<script runat="server">
Public Sub Page_Load()

If Request.QueryString("url") <> "" Then
Response.Redirect Request.QueryString("url")
Else
Response.Redirect ("http://www.example/default.aspx")
End If

End Sub
</script>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #6

Thanks for the correction, however when I link to this file from another
page, I get an error:

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: BC30800: Method arguments must be enclosed in
parentheses.

Source Error:
Line 4:
Line 5: If IsPostBack Then
Line 6: Response.Redirect Request.QueryString("url")
Line 7: Else
Line 8: Response.Redirect
("http://www.example.com/default.aspx")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #7
Thanks for your help the following code seems to achive what I am
looking for.

<code>

<%@ Page Language="vb" enableviewstate="False"%>
<script runat="server">
Public Sub Page_Load()

If IsPostBack Then
Response.Redirect (Request.QueryString("url"))
Else
Response.Redirect ("http://www.example.com/default.aspx")
End If

End Sub
</script>

</code>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #8
It just means that in .NET, you must pass method arguments in parenthesis.
Your first redirect doesn't have any parenthesis. Try this:
If IsPostBack Then
Response.Redirect(Request.QueryString("url"))
Else
Response.Redirect("http://www.example.com/default.aspx")
End If

"Terry Ashley" <te**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

Thanks for the correction, however when I link to this file from another
page, I get an error:

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: BC30800: Method arguments must be enclosed in
parentheses.

Source Error:
Line 4:
Line 5: If IsPostBack Then
Line 6: Response.Redirect Request.QueryString("url")
Line 7: Else
Line 8: Response.Redirect
("http://www.example.com/default.aspx")

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
4
by: TomT | last post by:
Hi.. I'm redirecting users to another page using: response.redirect("newpage.asp") this works... But I need to add a variable to the page specified.. IE: newpage.asp?id=JobID
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
2
by: darrel | last post by:
I've been struggling with a page that is set up like this: PAGE: ------------------ control 1 - reads a cookie and executes stuff based on that control 2 - reads the same cookie and can also...
8
by: Daniel | last post by:
Hello, I have an old asp page that was used to redirect users called redirect.asp: <code1> <% Option Explicit If Request.QueryString("url") <> "" Then Response.Redirect ...
1
by: stevebremermn | last post by:
I'm working on setting up some affiliate links on a site of mine and I haven't been able to get a redirect to work. The original affiliate link looks like this: ...
5
by: venner | last post by:
I'm having an issue with an ASP.NET website after upgrading to ASP.NET 2.0. The website makes use of a central authentication service (CAS) provided at the university I work for. Each page checks...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
1
by: Culley | last post by:
I've created a secure login site. Everything works fine except for one thing... the redirect. I want to redirect users to the correct page they are accessing (say they're just clicking a link...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.