Click to See Complete Forum and Search --> : Response.redirect & window.close


simon315
12-24-2003, 11:56 PM
Hi. I've got a question that I cannot seem to make work. I've got a page that when a user clikcs on a link it popups a page that allows them to login to the site. Once they click on submit, the username and password are then authenticated and based on which username they used, they are then directed to a specific page (which could be one page of many different choices). My problem is that once they user is properly authenticated I need two things to happen:
1. the user must be redirected to their specific page, but the page they clicked on to get the login pop-up is the page that needs to be redirected, not the login page.
2. the login page needs to close once they have been authenticated and the proper page has been redirected.

I've tried to use Javascript mixed in within the ASP to make this work, but I can only get the window to close on it's own. I can't figure out how to get the original page to be redirected. Can someone please help? Here is the code I'm working with:

<!--#include file="login_conn.asp"-->
<%
User = Request.Form("username")
Pass = Request.Form("password")

'Create the RecordSet
Set RS = Server.createObject("ADODB.recordset")
SQL = "Select *From clients WHERE User_Name in('"&User&"') and User_Password in('"&Pass&"')"
RS.Open SQL, objConn

'Check to see if username and password are in database, if not redirect them
If RS.EOF Then
Session("LoggedIn") = 0
Session("UserID") = 0
Response.Redirect("../extranet3/login_failure.htm")
Else
Area = RS("User_Client_Area")
Session("LoggedIn") = Area
Session("UserID") = RS("User_ID")
'Kill the RecordSet
RS.Close
'If user is found, update the LAST_LOGIN field
Set RS = Nothing
SQL = "Update clients Set User_Last_Login = Now() WHERE User_Name = '"&User&"' AND User_Password = '"&Pass&"'"
ObjConn.Execute(SQL)

'Kill the Database Connection
ObjConn.Close
Set ObjConn = nothing

'Redirect user after authentication
If Area = 1 Then Page = "client1/index.asp"
If Area = 2 Then Page = "xxx/index.asp"
Response.redirect(Page)
Response.Write("<SCRIPT>window.close()</SCRIPT>")
End if
%>

Thanks in advance!

Simon315

ray326
12-25-2003, 11:45 PM
You can't simply use redirect for this. What you should try to do from the login page is set the location of its opener based on the authenticated user then close itself.

simon315
12-26-2003, 12:39 AM
Well at the bottom of the code I've displayed, i do have it redirecting to a page based on the user, but that's after authentication has taken place. Is there a wimplier way? I'm trying to figure this out, but I guess it must be escaping me. I want to make this as simple as possible so I don't have to make 50 changes to 50 different documents later on down the road. Thanks!

ray326
12-26-2003, 01:40 PM
I use the web server's authentication mechanism so a user coming into the site is presented with the browser's login dialog. After that I know who the REMOTE_USER is and can act accordingly.

I also try to never open additional windows because they're messy to deal with and they almost always confuse a lot of users. In your scenario, you might be better off just redirecting to the login page rather than popping it up. Then you can forward them on in the same window without the aditional bean counting.

simon315
12-26-2003, 07:45 PM
I had thought about that, but what the client wants, the client gets. I tried telling them, but that's what they "need". Is there any other way to add maybe a respone.write script in there? Or is that getting way too complex?

ray326
12-27-2003, 01:46 AM
I just tell a client like that, "Look, I can do what you thing you want or I can do it right. The former is going to be a lot more expensive and a lot less secure AND it will break when new browsers come around so it will be even more expensive later on." Unless they're total idiots they usually get the hint.

I'll outline a strategy for doing what you want but you'll have to prove it.

1. Window1/Page1 - discover the user needs to authenticate to continue.

2. Window1/Page1 - open a new window (Window2) with the login form (Page2).

3. Window2/Page2 - validate the login credentials, resulting in Page3.

4. Window2/Page3 - set the location of the window opener (Window1) to the desired URL. I.e., forward Window1 to Page4.

5. Window2/Page3 - close this window.

Very expensive, very messy, very fragile.