• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 832
  • Last Modified:

ASP code displaying blank page

I'm currently registering users according to the below criteria:

If rsUser.recordCount > 0 Then
Response.Cookies("adminID")      = rsUser("adminID")
Response.Cookies("adminName")      = rsUser("adminName")
Response.Redirect "../main.asp"
Else
Response.Redirect "../loginFailure.asp"
End If

I need to put another condition like this:

If user AccessLevel = '0' then response.redirect main1.asp
If user AccessLevel = '1' then response.redirect main2.asp

I tried to incorporate the code inside main.asp, like below, but it doesn't work (it gives a blank page)

<% if session("AccessLevel")="1" then
response.redirect = "main1.asp"
elseif session("AccessLevel")="0" then
response.redirect = "main2.asp"            
end if %>

What am I doing wrong?
The code can also be incorporated inside main.asp. I tried but that also gives a blank page.



0
zamorin
Asked:
zamorin
  • 4
  • 4
1 Solution
 
tirandaganCommented:
It looks like you forgot to set the session variable ("AccessLevel").
I assume your login validation should contain something like:

session("AccessLevel") = rsUser("AccessLevel")

Because from the example you provided,  session("accessLevel") is not being set, so is = NULL, so both conditions fail and what you are left with is the rest of the main.asp file, which is nothing (ego, blank page)
0
 
zamorinAuthor Commented:
Where do I set it?
0
 
zamorinAuthor Commented:
I tried this, but it doesn't work:

      If rsUser.recordCount > 0 Then
            Response.Cookies("adminID")                  = rsUser("adminID")
            Response.Cookies("adminName")            = rsUser("adminName")
            Response.Cookies("AccessLevel")            = rsUser("AccessLevel")
            Response.Redirect "../main.asp"
      Else
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
weddellCommented:
You have
response.redirect = "main2.asp"

try

response.redirect("main2.asp")
0
 
weddellCommented:
<%

If Session("AccessLevel")="1" Then
    Response.Redirect("main1.asp")
ElseIf Session("AccessLevel")="0" Then
    Response.Redirect("main2.asp")
Else
    Response.Write("this isn't a blank page")
End If

%>

All Zamorin meant about setting it is that it isn't assigned a value in the script you posted...

So above the condition you write

Session("AccessLevel") = 1 ' or get this from the database

Response.Redirect is a method not a property, therefore = should not be included

Ciao.
0
 
zamorinAuthor Commented:
Now if I login with AccessLevel 1 or 0 it displays the message:
this isn't a blank page

Do I have to set Session("AccessLevel")  somewhere?

The AccessLevel is retreived from the database.
0
 
weddellCommented:
yes.. you have to set it to the database value... see below where rsUser("adminLevel") is your column name in the database (ensure it's coming back in your SQL statement as well)

If rsUser.recordCount > 0 Then
    Response.Cookies("adminID") = rsUser("adminID")
    Response.Cookies("adminName") = rsUser("adminName")
    Session("AccessLevel") = rsUser("adminLevel")

    If Session("AccessLevel") = "1" Then
        Response.Redirect("main1.asp")
    ElseIf Session("AccessLevel") = "0" Then
        Response.Redirect("main2.asp")
    Else
        Response.Write("no admin level was found")
        Response.End
    End If

Else
    Response.Redirect("../loginFailure.asp")
End If
0
 
zamorinAuthor Commented:
Works perfectly!
0
 
weddellCommented:
Thanks for the points and comment. For your info, this script is a little more refined and may be useful if you add more access levels later:

Dim pagePath

' Login Failure Page
pagePath = "../loginFailure.asp"

If rsUser.recordCount > 0 Then

      Response.Cookies("adminID") = rsUser("adminID")
      Response.Cookies("adminName") = rsUser("adminName")
      Session("AccessLevel") = rsUser("adminLevel")

      Select Case Trim(Session("AccessLevel"))
            Case "0"
                  ' Standard Membership
                  pagePath = "../main2.asp"
            Case "1"
                  ' Premium Membership
                  pagePath = "../main1.asp"
      End Select

End If

Response.Redirect(pagePath)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now