Writing few messages before displaying a desired page

Discussion in 'ASP General' started by Jack, Nov 12, 2004.

  1. Jack

    Jack Guest

    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
     
    Jack, Nov 12, 2004
    #1
    1. Advertising

  2. 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


    "Jack" <> wrote in message
    news:D...
    > 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
     
    Ray Costanzo [MVP], Nov 12, 2004
    #2
    1. Advertising

  3. Jack

    Jack Guest

    I got it Ray, Thanks for the help.

    "Ray Costanzo [MVP]" wrote:

    > 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
    >
    >
    > "Jack" <> wrote in message
    > news:D...
    > > 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

    >
    >
    >
     
    Jack, Nov 12, 2004
    #3
  4. Jack

    Paxton Guest

    "Jack" <> wrote in message
    news:D...
    > 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.
     
    Paxton, Nov 12, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eJAYBee
    Replies:
    0
    Views:
    494
    eJAYBee
    Dec 10, 2004
  2. Murali
    Replies:
    2
    Views:
    577
    Jerry Coffin
    Mar 9, 2006
  3. SteveC
    Replies:
    2
    Views:
    448
    SteveC
    Jul 30, 2008
  4. bg
    Replies:
    0
    Views:
    107
  5. techy techno
    Replies:
    0
    Views:
    103
    techy techno
    Feb 4, 2004
Loading...

Share This Page