Writing few messages before displaying a desired page

J

Jack

Hi,
I have the following code as a part of authenticating a system.
If Rs.eof Then
Session("Authenticated") = 0
Response.Write "Sorry, your userid or password did not match"
Response.Write "<BR>"
Response.Write "or you have not registered yet. Please register"
Response.Redirect("login.asp")
Else
Session("Authenticated") = 1
Response.Redirect ("Welcome.asp")
End If
In the first if statement, I would like to display the above messages
before forcing the login.asp page to display. Is is possible to do both
message and contents of login.asp in the same page? Thanks
 
R

Ray Costanzo [MVP]

With Windows 2000 and above, response buffering is on by default. So, your
response.write statements won't ever make it to the browser since you then
send a redirect. If you were to turn off buffering, you'd see that this
actually causes an error. You cannot send a redirect command to the browser
after sending back response text. So, no, you cannot do what you're trying
to do, exactly. You can do:

<% If Rs.eof Then
Session("Authenticated") = 0
%>

Sorry, your userid or password did not match<br>or you have not registered
yet. Please register.
<a href="login.asp">Click me</a>

Ray at work
 
J

Jack

I got it Ray, Thanks for the help.

Ray Costanzo said:
With Windows 2000 and above, response buffering is on by default. So, your
response.write statements won't ever make it to the browser since you then
send a redirect. If you were to turn off buffering, you'd see that this
actually causes an error. You cannot send a redirect command to the browser
after sending back response text. So, no, you cannot do what you're trying
to do, exactly. You can do:

<% If Rs.eof Then
Session("Authenticated") = 0
%>

Sorry, your userid or password did not match<br>or you have not registered
yet. Please register.
<a href="login.asp">Click me</a>

Ray at work
 
P

Paxton

Jack said:
Hi,
I have the following code as a part of authenticating a system.
If Rs.eof Then
Session("Authenticated") = 0
Response.Write "Sorry, your userid or password did not match"
Response.Write "<BR>"
Response.Write "or you have not registered yet. Please register"
Response.Redirect("login.asp")
Else
Session("Authenticated") = 1
Response.Redirect ("Welcome.asp")
End If
In the first if statement, I would like to display the above messages
before forcing the login.asp page to display. Is is possible to do both
message and contents of login.asp in the same page? Thanks

It is possible to do what you want - if you put the authentication checking
code on the same page as the log-in form, and post it to itself

dim strMessage
strMessage = "Please enter your Userid and Password"

If RS.EOF Then
Session("Authenticated")=0
strMessage = "Sorry, your userid or password did not match <br>"
strMessage = strMessage & "or you have not registered yet. Please
Register"
Else
..... etc, etc

then pop <%=strMessage%> in the appropriate place on the form page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top