Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Redirect

Status
Not open for further replies.

jojo79

Programmer
Oct 11, 2006
40
US
I am attempting to redirect users when there session var does not equal 2. I have been having no luck with my code below,

The page is an .net page. Any help would be valuable. Thanks you

Code:
<%If Session("Usr_Group") != "2" then %>
<script LANGUAGE='Javascript'>
alert('You are being redirected to the Login Screen')
top.location.href="logon.asp"
</script>
<%End IF%>
 
trollacious has a good point.

Still, it is not just about getting to the login page. It is the experience of seeing the message in the alert box. How would we do that, and why doesnt it work for jojo?

One issue is the placement of the Javascript in the page. I assume there is more to this page than the alert box. I think that the timing of the execution of the Javascript is affected by where it is placed. One way to control this is to use the onload event in the <BODY> tag. Set it to call a function, and write the variable Javascript inside that function. This way the whole page will be loaded in the client computer before the function is called. If the redirect code has been written by ASP, then it runs; otherwise nothing happens.

 
If you want the alert on the page, try something like this:
Code:
<%If Session("Usr_Group") [b][red]<>[/red][/b] "2" then %>
<script LANGUAGE='Javascript'>
alert('You are being redirected to the Login Screen')
location.href="logon.asp"
</script>
<%
Response.Flush
Response.End
End IF%>

This time use the VB Not Equals <> rather than the C version.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top