Redirect after login based on Access Level

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Redirect after login based on Access Level

    Hi All

    I have been working through the tutorial on
    [url]http://dmxzone.com/showDetail.asp?TypeId=28&NewsId=7645[/url] to try and work out how
    to redirect a user to a page based on their access level (E.G. people with
    acces level 1 go to page1.asp with access level 2 go to page2.asp). I have
    worked through the tutorial but as soon as I insert the code to redirect the
    user it starts to go wrong. When I try to signin the username and password are
    not recognised. The txtfields and database fields are all linked correctly
    because as soon as I remove the redirect code it works as it should.

    The redirect code is as follows:

    ' redirect user based on Access level
    If Session("MM_UserAuthorization") = "2" Then
    MM_redirectLoginSuccess = "../AccessLevel1.asp"
    ElseIf Session("MM_UserAuthorization") = "3" Then
    MM_redirectLoginSuccess = "../AccessLevel2.asp"
    Else MM_redirectLoginSuccess = "?Action=Failed"
    End If

    The complete code is at the bottom of this message

    Any help would be greatly appreciated as I can't see were I am going wrong..

    Cheers....Doug

    <%
    ' *** Validate request to log in to this site.
    MM_LoginAction = Request.ServerVariables("URL")
    If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" +
    Server.HTMLEncode(Request.QueryString)
    MM_valUsername=CStr(Request.Form("txtUsername"))
    If MM_valUsername <> "" Then
    MM_fldUserAuthorization="AccessLevelId"
    MM_redirectLoginSuccess="welcome.asp"
    MM_redirectLoginFailed="default.asp?Action=Failed"
    MM_flag="ADODB.Recordset"
    set MM_rsUser = Server.CreateObject(MM_flag)
    MM_rsUser.ActiveConnection = MM_ConMiddlehavenResources_STRING
    MM_rsUser.Source = "SELECT FldUsername, FldPassword, UserId"
    If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source &
    "," & MM_fldUserAuthorization
    MM_rsUser.Source = MM_rsUser.Source & " FROM TblUsers WHERE FldUsername='" &
    Replace(MM_valUsername,"'","''") &"' AND FldPassword='" &
    Replace(Request.Form("txPassword"),"'","''") & "'"
    MM_rsUser.CursorType = 0
    MM_rsUser.CursorLocation = 2
    MM_rsUser.LockType = 3
    MM_rsUser.Open
    If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
    If (MM_fldUserAuthorization <> "") Then
    Session("MM_UserAuthorization") =
    CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization ).Value)
    Else
    Session("MM_UserAuthorization") = ""
    End If

    ' redirect user based on Access level (added by Doug)
    If Session("MM_UserAuthorization") = "2" Then
    MM_redirectLoginSuccess = "../AccessLevel1.asp"
    ElseIf Session("MM_UserAuthorization") = "3" Then
    MM_redirectLoginSuccess = "../AccessLevel2.asp"
    Else MM_redirectLoginSuccess = "?Action=Failed"
    End If

    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
    MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginFailed)
    End If
    %>

    Dougsie Guest

  2. Similar Questions and Discussions

    1. Forms-Based Security below Application Level
      If I have a site where I want to use Forms-Based security but only on one or two SUB-directories of the Application root, I'm confused about how...
    2. Page Level role-based authentication
      I've set up and managed to use ASP.NET role-based authentication. I find the automatic checking and redirecting for unauthorized pages really...
    3. Flash redirect based on URL
      I need to be able to redirect people from a url string from within flash. for example www.fx-digital.com/pres?on1019 plays the flash movie and then...
    4. Domain-based Redirect
      Sorry code should look somewhat like this: $referer = trim($_SERVER); if ( $referer == "http://www.mydomain.com/A" ) { header("Location:...
    5. Page level, IP based security...
      I have a Web Project containing two WebForms and one WebService. What's the best way to limit who is able to access those three items? I want the...
  3. #2

    Default Re: Redirect after login based on Access Level

    I think there's and End If missing in the code you're inserting.

    Try that.
    Darklomba Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139