We help IT Professionals succeed at work.

Passing Session Variables with Response Redirect Classic ASP

LT1415
LT1415 asked
on
I am using classic asp vb script
I need to redirect to another page and include the session variable, user name in the redirection URL

If a place a link on the redirect page and click it, I can pass the session variables this way
<a
href="http://blah//Default.aspx?username=<%=Se
ssion("UserName")%>" target="_blank">

But I do not want the user to have to click that link, I just want the page to redirect there and pass the username credentials in the URL

I tried something like this
<%          
 Dim userName
 username = Request.QueryString("UserName")
if(userName <> "") Then
Response.Redirect("http://blah//Default.aspx?u
sername=<%=Session("UserName")%>", False)
 End if
%>

But got an error
Microsoft VBScript compilation error '800a03ee'

Expected ')'

Thanks.


Comment
Watch Question

Commented:
Are you aware that you do not need to pass session variables within the same application?
You can only call the session variable in the next page.

Hence session variable, it is available on all pages throughout the app for that users session.
Top Expert 2010

Commented:
Try:

<%          
 Dim userName
 username = Request.QueryString("UserName")
 if userName <> "" Then
      Response.Redirect "http://blah//Default.aspx?username=" & Session("UserName")
 End if
%>
Senior Solution Architect
Commented:
you need to remove the parenthesis "(" from the Response Redirect.

Also there is no need to have the Session("UserName") variable inside <% %> (server tags)
because you have already opened them just before the Dim keyword


<%          
Dim userName
username = Request.QueryString("UserName")
if(userName <> "") Then
Response.Redirect "http://blah//Default.aspx?username=" & Session("UserName"), False
 End if
%>

Open in new window