user3708338
user3708338

Reputation: 1

How to set custom header and redirect to specific location

I am trying to set a custom header variable after doing a lookup in SQL Server and then redirect the user while still having access to the variable. I have tried:

Response.Addheader "custvar", customvariable

Response.Redirect("http://example.com")

But when I get to example.com the header is not present. Is there another way to do this? I am using IIS and have tried the simple ASP above so far.

Upvotes: 0

Views: 4602

Answers (3)

silver
silver

Reputation: 630

Add the custom header as per instructed here

adding custom header with classic asp

and then add the redirect manually without the re-direct

eg.

 Response.Addheader "custvar", customvariable
 Response.Status="301 Moved Permanently"
 Response.AddHeader "Location", "http://www.thenewpage.com"

Upvotes: 0

allski
allski

Reputation: 86

I agree with @dotnetom. I use response.redirects with variables passed in query string very successfully throughout my application to achieve this result along with variable i wish to pass. Non sensitive data caveat of course also.

Upvotes: 0

dotnetom
dotnetom

Reputation: 24901

I don't think it is possible to do it with header.

What Response.Redirect effectively does is it sends the 302 result (Found or Moved Temporarily) to a browser. Then browser makes another call to the address which was provided in 302 result. This means that you are creating a response header for 302 result, but this header has no way to be used in subsequent result to example.com.

If you want to pass some information between requests and request is made to the same site you could set a cookie and it will be sent during your redirect. If you control the site where you redirect to you can also use query string to pass the required parameters. Of course you should not add sensitive information to either cookie or query string.

Upvotes: 1

Related Questions