473,406 Members | 2,356 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,406 software developers and data experts.

Response.Redirect

Hi

I need to write a method which accepts a url (string) and redirects to it.
In addition to this I need to either (a) add a parameter to the url; or (b)
add the parameter to the header of the redirect request.

To add a parameter I guess it's as easy as adding "?myparam=myvalue" to the
url (or "&myparam=myvalue" if there already are parameters in the url string
I get).

But how do I add a header? Can I use Request.Headers.Add("myparam",
myvalue), and then do a Redirect?

Thanks,
Peter
Feb 3 '06 #1
3 5082
Peter,

When you redirect, a 302 response is sent back to the client. It is the
client that then gets the URL to redirect to, and the client which
subsequently makes the request. Because of this, you can't change the
headers that are sent.

What you want to do is call the Transfer method on the HttpServerUtility
(the Server property on the page, or the HttpContext) to transfer processing
to another page. You can opt to keep the form properties that were sent in
the initial request.

However, you will not be able to append any values to the Form values
sent with the request. While Form returns a NameValueCollection, it does
not allow you to add elements to it once it is populated.

Rather, what you should do is encode the information in the URL, or have
a key that you append to the URL which points to something in session state
that your page can retreive.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi

I need to write a method which accepts a url (string) and redirects to it.
In addition to this I need to either (a) add a parameter to the url; or
(b) add the parameter to the header of the redirect request.

To add a parameter I guess it's as easy as adding "?myparam=myvalue" to
the url (or "&myparam=myvalue" if there already are parameters in the url
string I get).

But how do I add a header? Can I use Request.Headers.Add("myparam",
myvalue), and then do a Redirect?

Thanks,
Peter

Feb 3 '06 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> skrev i
en meddelelse news:%2***************@TK2MSFTNGP09.phx.gbl...
When you redirect, a 302 response is sent back to the client. It is
the client that then gets the URL to redirect to, and the client which
subsequently makes the request. Because of this, you can't change the
headers that are sent.

What you want to do is call the Transfer method on the
HttpServerUtility (the Server property on the page, or the HttpContext) to
transfer processing to another page. You can opt to keep the form
properties that were sent in the initial request.

However, you will not be able to append any values to the Form values
sent with the request. While Form returns a NameValueCollection, it does
not allow you to add elements to it once it is populated.

Rather, what you should do is encode the information in the URL, or
have a key that you append to the URL which points to something in session
state that your page can retreive.


Thanks for your reply. I'm not sure I can use your advice however.

Maybe if I restate the actual problem I am trying to solve, then someone can
give some advice on how to tackle it (rather than me assuming a particular
method of solving the problem).

I have a web-user-control which needs to "call" an external url (or transfer
control to that url... or whatever it is called in the web world). My
control receives some parameters from which it determines what external url
to call. My control also receives some other parameters which need to be
sent on to the external url.

The external urls expect to receive the parameters either like a "get
request": fx http://www.e-data.xx?myparam=myvalue; or they may expect to
found the parameter values in the request header.

Any advice on tackling this?
Thanks,
Peter


Feb 3 '06 #3
Peter,

In this case, you have to use the GET method to form the particular URL,
and use a redirect for the reasons I stated regarding the browser making the
request. You can't tell it what headers to send, but you can tell it the
URL to go to.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:u8*************@TK2MSFTNGP12.phx.gbl...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> skrev i
en meddelelse news:%2***************@TK2MSFTNGP09.phx.gbl...
When you redirect, a 302 response is sent back to the client. It is
the client that then gets the URL to redirect to, and the client which
subsequently makes the request. Because of this, you can't change the
headers that are sent.

What you want to do is call the Transfer method on the
HttpServerUtility (the Server property on the page, or the HttpContext)
to transfer processing to another page. You can opt to keep the form
properties that were sent in the initial request.

However, you will not be able to append any values to the Form values
sent with the request. While Form returns a NameValueCollection, it does
not allow you to add elements to it once it is populated.

Rather, what you should do is encode the information in the URL, or
have a key that you append to the URL which points to something in
session state that your page can retreive.


Thanks for your reply. I'm not sure I can use your advice however.

Maybe if I restate the actual problem I am trying to solve, then someone
can give some advice on how to tackle it (rather than me assuming a
particular method of solving the problem).

I have a web-user-control which needs to "call" an external url (or
transfer control to that url... or whatever it is called in the web
world). My control receives some parameters from which it determines what
external url to call. My control also receives some other parameters which
need to be sent on to the external url.

The external urls expect to receive the parameters either like a "get
request": fx http://www.e-data.xx?myparam=myvalue; or they may expect to
found the parameter values in the request header.

Any advice on tackling this?
Thanks,
Peter

Feb 3 '06 #4

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...
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...
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...
9
by: RN1 | last post by:
When a server encounters the line Response.Redirect("abcd.asp") in a ASP script, the server tells the browser that it has to be redirected to another page (which is abcd.asp, in this case)....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.