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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.redirect method not working

Status
Not open for further replies.

axslearnr

Technical User
Apr 1, 2004
78
US
hi
My page is not redirecting to Admin_Menu.asp using Response.Redirect method. it enters the security level = 1 but displays back the login page not the Admin_page. But the same thing is working on another computer. this same script works on another computer. my ASP and access mdb database r on the IIS server.

can anyone tell me why its happening

thank you


'Open correct menu page based on user security level
Select Case session("SecurityLvl")
Case 4: If session("SecurityLvl") = 4 Then Response.Redirect "Employee_Menu.asp"
Case 3: If session ("SecurityLvl") = 3 Then Response.Redirect "Mgmt_Menu.asp"
Case 2: If session ("SecurityLvl") = 2 Then Response.Redirect "DataEntry_Menu.asp"
Case 1: If session ("SecurityLvl") = 1 Then Response.Redirect "Admin_Menu.asp"
Case Else: Response.Redirect "Metrics_Logon.asp"
End Select


%>

<!-- #include file="Include_Files/General/Disconnect.inc" -->
 
Try doing a cInt on in your Select Case or specify the cases to be strings rather than numbers ("1","2",etc). It could just be a type matchig issue.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
hi
i tried that it didnt work. it is actually entering the securlity level - 1 means valdaiting butits just not redirecting the page to Admin_Menu.asp. when i use Server.Transfer it redirects the page to Admin_Menu.asp.

can u pls tell what is the problem
thank you
 
Maybe you should try this way
Code:
Select Case session("SecurityLvl")
    Case 4
        Response.Redirect "Employee_Menu.asp"
    Case 3
        Response.Redirect "Mgmt_Menu.asp"
    Case 2
        Response.Redirect "DataEntry_Menu.asp"
    Case 1
        Response.Redirect "Admin_Menu.asp"
    Case Else
        Response.Redirect "Metrics_Logon.asp"
End Select
I'm not shure it couldnt like the : thing.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
The fact that server.transfer works makes me think you may have some dependance on form values being passed along. Server.Transfer makes those values available to the new page, but response.redirect makes the client browser change pages, so any submitted form values are lost.
If I had to guess I would guess that your passing authentication information along in form or querystring values. Then at the top of your admin page your checking those values to make sure they're logged in and if they aren't logged in rediecting to the login page. When you use response.Redirect you lose that authentication info so it directs to the login page thinking they aren't logged in. When you use Server.Transfer you don't lose the authentication information so it continues to display the admin page.

The quickest way to test this would be to put a Response.Write "something" at the top of your admin page before anything else, then follow that with a Response.End.
If you see that content the next time you test it with response.redirect than my conclusions are correct and you are dependant on some form value that is getting left behind.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
hi
i tried that i still got the same User_logon page. i have only three fields on logon page username password and security level.
thank u for your help i really appreciate that.

can u pls tell what could be the problem

 
Hrmm, it seems that what you would select it would go there.
Try to do a Response.Write session("SecurityLvl") and see what's it's value... Maybe your session is lost somewere.


________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
hi
i tried that tto in Admin_menu asp page but its still the same USer_Logon page. i even tried putting in the Security_Page it shows me the security value of 1 until select case : securitylvl=1 statement. it even entered the if clause of that statement but it doesnt redirect the page

pls let me know
thank you


 
Maybe you should use Response.End also.
Code:
Select Case int(session("SecurityLvl"))
    Case 4
        Response.Redirect "Employee_Menu.asp"
        Response.End
    Case 3
        Response.Redirect "Mgmt_Menu.asp"
        Response.End
    Case 2
        Response.Redirect "DataEntry_Menu.asp"
        Response.End
    Case 1
        Response.Redirect "Admin_Menu.asp"
        Response.End
    Case Else
        Response.Redirect "Metrics_Logon.asp"
        Response.End
End Select
Try exactly this code.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
hi
i tried that too it didnt work. as i told before this code works perfectly on another computer and also when i lcally installed webserver and run it its working too.

it just doesnt run the netwrok server. it only runs on one computer.

psl let me know
bye
 
I don't know how your entire ASP page is set up, however with Response.Redirect, you cannot have ANY HTML before calling this method..

Do you get an error message at all?

G.

GT Interactive
-----------------------------
Components/Tools/Forums/Software/Web Services
 
hi
i dont get any error message. its just redirects to the User_login Asp page.

This is my User_Security page

'Declare all local variables
Dim conn ' ADO connection
Dim RST ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file
Dim strSQL ' SQL statement for recordset
Dim userName
Dim testcodevalue ' Determines if to check security code in employee table.
' If set to 0 then check code. If set to -1 check security code
' on Logon display.

' MapPath of virtual database file path to a physical path.
strDBPath = Server.MapPath("User_Assets.mdb")
On Error Resume Next
' Create an ADO Connection to connect to the sample database.</FONT>
set conn = Server.CreateObject("ADODB.Connection")


'Use ODBC DSN to link to MS Access database
conn.open "DSN=usrdsn;uid=" & Request("Userid") & ";pwd=" & Request("Password")
if err.number < 0 then 'Could not make connection. Return to main display
Response.Redirect "User_Logon.asp?msg=1"
end if

'Set session Userid and Password variables
session("Userid") = Request("Userid")
session("Password") = Request("Password")
session("ClassDate") = Date()

testcodevalue = GetTestCodeValue()
if testcodevalue = "-1" then
session("SecurityLvl") = Request("EmployeeID")


if session("SecurityLvl") = "" or isnull(session("SecurityLvl")) then
'Forgot to enter security level. Return to main display.
Response.Redirect "User_Logon.asp?msg=-1"
end if

end if


'Open recordset for based on userid
userName = session("Userid")
set RST=Server.CreateObject("adodb.recordset")
strSQL = "SELECT [First Name], [Last Name], [Employee Status ID], [Employee ID], [Security_Level] FROM employee WHERE UserName = '" & userName & "';"

RST.open strSQL, conn




'Set session Employee ID and Name variables
session("EmployeeName") = RST("First Name") & " " & RST("Last Name")
session("EmployeeID") = RST("Employee ID")
if testcodevalue <> "-1" then
session("SecurityLvl") = RST("Security_Level")
if session("SecurityLvl") = "" or isnull(session("SecurityLvl")) then
Session("SecurityLvl") = 4
end if

end if

'Add Audit Record
Add_Audit session("Userid"), "User_Logon", "Logon", "", "", Now()

'Open correct menu page based on user security level
Select Case session("SecurityLvl")
Case 4: If session("SecurityLvl") = 4 Then Response.Redirect "Employee_Menu.asp"
Case 3: If session ("SecurityLvl") = 3 Then Response.Redirect "Mgmt_Menu.asp"
Case 2: If session ("SecurityLvl") = 2 Then Response.Redirect "DataEntry_Menu.asp"
Case 1: If session ("SecurityLvl") = 1 Then Response.Redirect "Admin_Menu.asp"
Case Else: Response.Redirect "User_Logon.asp"
End Select


%>

<!-- #include file="Include_Files/General/Disconnect.inc" -->

This is my User_Logon.asp page

<!-- #include file="Include_Files/General/GetTestCodeValue.inc" -->


<%
Dim msg1, msg2, msgtest
Dim TestMode

TestMode = GetTestCodeValue

msg1 = " Either your userid or password is invalid!"
msg2 = " Your password is not valid!"
msg3 = " You did not enter a valid security code!"
msg = ""

if cint(request.querystring("msg")) = 1 then
msg = msg1

else
if cint(request.querystring("msg")) = 2 then
msg = msg2
else
if cint(request.querystring("msg")) = -1 then
msg=msg3
end if

end if
end if

%>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Employee Logon</title>
<script Language="JavaScript"><!--
function FrontPage_Form1_Validator(theForm)
{

if (theForm.Password.value == "")
{
alert("Please enter a value for the \"Password\" field.");
theForm.Password.focus();
return (false);
}

if (theForm.Password.value.length < 1)
{
alert("Please enter at least 1 characters in the \"Password\" field.");
theForm.Password.focus();
return (false);
}

if (theForm.Password.value.length > 25)
{
alert("Please enter at most 25 characters in the \"Password\" field.");
theForm.Password.focus();
return (false);
}
return (true);
}

function disable(formnum, elementnum) {
if (navigator.appName == "Microsoft Internet Explorer")
document.forms[formnum].elements[elementnum].style.visibility="hidden";
}


function enable(formnum, elementnum) {
if (navigator.appName == "Microsoft Internet Explorer")
document.forms[formnum].elements[elementnum].style.visibility="inherit";
}


//--></script>
</head>
<body bgcolor="#FFFFFF" >
<form method="POST" action="User_Security.asp" name="FrontPage_Form1" onload="disable(0,2)" onsubmit="return FrontPage_Form1_Validator(this)">
<table border="0" cellspacing="0" cellpadding="0" width="633" height="377">
<tr><td width="154" height="47"><img border="0" src="images/Logo.gif"></td><td width="646" height="47"><img border="0" src="images/TitleMain.gif"></td></tr>
<tr><td colspan="2" width="800" height="80"><img border="0" src="images/TopLine.gif"></td></tr>
<tr><td width="167" height="377"><img border="0" src="images/leftbar.gif"></td><td width="633" height="377" valign="top"><br>

<form method="POST" action="User_Security.asp" name="FrontPage_Form1" onsubmit="return FrontPage_Form1_Validator(this)">
<table border="0" cellspacing="0" width="50%">
<tr>
<td width="50%"><font face="Arial" size="3"><b>Name:</b></font></td>
<td width="50%"><font face="Arial" size="3"><INPUT TYPE="text" name="Userid" size="25" tabindex="1" maxlength="25"></font></td>
</tr>
<tr>
<td width="50%"><font face="Arial" size="3"><b>Password:</b></font></td>
<td width="50%"><font face="Arial" size="3"><input type="password" name="Password" size="25" maxlength="25" tabindex="2"></font></td>
</tr>
<tr>
<td width="50%"><font face="Arial" size="3" <% if TestMode = "-1" then %> style="visibility:visible" <% else %> style="visibility:hidden" <% end if %>>Security:</font></td>
<td width="50%"><font face="Arial" size="3"><input type="text" name="EmployeeID" size="25" maxlength="25" tabindex="2" <% if TestMode = "-1" then %> style="visibility:visible" <% else %> style="visibility:hidden" <% end if %> ></font></td>
</tr>

</table>

<br><br><br>
<p><input type=image src="images/B_Logon_Off.gif" value="Login" name="Submit" onmouseover="src='images/B_Logon_On.gif'" onmouseout="src='images/B_Logon_Off.gif'"></p>

<br>
<%
response.write "<b><font color='FF0000' size='4'>" & msg

%>
</form>
</TD>
</TR>



</form>



<tr><td width="800" height="96" colspan="2">
<img border="0" src="images/footer.gif">
</td></tr>
</table>
</body>


 
Check to make sure that the browser your using is allowing cookies. If it is blocking the initial session cookie that IIS is serviing out then all of the session information your setting won't be associated with your browser, so during the redirect you will be coming to the site fersh and will have lost your authentication info.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
hi
I checked that. It is the browser problem. The code is running only on IE 5.5500 version. Its not running on IE 6.00 or IE 5.00. I dont know why. Atleast figured out with u guys help that it is the browser proble.

Now how to set the code to work for any IE browser version.
How to check the browser aloowing cookie seesion. I checked the enable cookies in my Inernet options of the IE browser.

Thank for ur help. I really appreciate that.

Pls let me know how to set this code for any IE browser version.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top