Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Link protection

Link protection

Scheduled Pinned Locked Moved ASP.NET
comtutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pforu1
    wrote on last edited by
    #1

    Dear All, I want to know how to protect a file from downloading if the user is not logged in;just the way its done here on codeproject? Suppose the file url is http://www.mydomain.com/photos.zip Download file Depending upon the login status it should either redirect to login page or proceed with download of the zip file, when download file link is clicked.I need the exact functionality of codeproject download feature. Thanking you all in advance.

    U 1 Reply Last reply
    0
    • P pforu1

      Dear All, I want to know how to protect a file from downloading if the user is not logged in;just the way its done here on codeproject? Suppose the file url is http://www.mydomain.com/photos.zip Download file Depending upon the login status it should either redirect to login page or proceed with download of the zip file, when download file link is clicked.I need the exact functionality of codeproject download feature. Thanking you all in advance.

      U Offline
      U Offline
      ublend
      wrote on last edited by
      #2

      Have you tried setting the navigateUrl property based on the status of their login? If variable <> "your logged in value" Then Me.HyperLink1.NavigateUrl = "" End If

      ublend

      P 1 Reply Last reply
      0
      • U ublend

        Have you tried setting the navigateUrl property based on the status of their login? If variable <> "your logged in value" Then Me.HyperLink1.NavigateUrl = "" End If

        ublend

        P Offline
        P Offline
        pforu1
        wrote on last edited by
        #3

        Hi, Buddy i forgot to mention earlier that the page is in Classic ASP as opposed to Asp.Net..Sorry for that. Please help.. Thanks P

        G U 2 Replies Last reply
        0
        • P pforu1

          Hi, Buddy i forgot to mention earlier that the page is in Classic ASP as opposed to Asp.Net..Sorry for that. Please help.. Thanks P

          G Offline
          G Offline
          Gary Stafford
          wrote on last edited by
          #4

          I dug up an old (2002 old) classic ASP/VB site I created that required the user to enter a username and password, which is checked against the database. If they are successful, a session variable in the global.asa file is set to true. Each page checks the variable first and bounces the user if the variable returns false. Top of each page:

          'Check if user is logged in
          Dim LoggedIn
          LoggedIn = Session("LoggedIn")
          If LoggedIn <> "True" Then
          Response.Redirect("login.asp")
          End If

          global.asa

          Sub Session_OnStart
          'Create a Session variable to track if the user has logged in
          Session("LoggedIn") = "False"
          ...
          End Sub

          Hope this helps.

          Regards, Gary

          1 Reply Last reply
          0
          • P pforu1

            Hi, Buddy i forgot to mention earlier that the page is in Classic ASP as opposed to Asp.Net..Sorry for that. Please help.. Thanks P

            U Offline
            U Offline
            ublend
            wrote on last edited by
            #5

            how are you authenticating your users? - If you are using a database to store their userID and password, you could use a script like this to signify that they are authenticated: ----use your database connection then check the form data against the data in your admin table like: Dim myPW, username,mystatus username=request("username") myPW=request("myPW") Set RSlog = Server.CreateObject("ADODB.Recordset") RSlog.Open "Select * from Admin where username='"&myLogin&"' and   password='"&myPW& "'", Conn, 2, 2 If not RSLog.eof or not RSLOG.eof then myStatus="IN" end if then lower in my page, where I want active links or not, I would code something like this: Response.Write ("<a href="yourURLorFilepath/" & RS("filename")& """>Link</a>") else response.write("link not available") end if Hope that helps. Happy coding

            ublend

            P 1 Reply Last reply
            0
            • U ublend

              how are you authenticating your users? - If you are using a database to store their userID and password, you could use a script like this to signify that they are authenticated: ----use your database connection then check the form data against the data in your admin table like: Dim myPW, username,mystatus username=request("username") myPW=request("myPW") Set RSlog = Server.CreateObject("ADODB.Recordset") RSlog.Open "Select * from Admin where username='"&myLogin&"' and   password='"&myPW& "'", Conn, 2, 2 If not RSLog.eof or not RSLOG.eof then myStatus="IN" end if then lower in my page, where I want active links or not, I would code something like this: Response.Write ("<a href="yourURLorFilepath/" & RS("filename")& """>Link</a>") else response.write("link not available") end if Hope that helps. Happy coding

              ublend

              P Offline
              P Offline
              pforu1
              wrote on last edited by
              #6

              Hi , I am using a session variable to store my login info. Actually I am looking for a solution exactly similar to what we have on this site. I dont want to display link not available. I have certain doc files,zip files for download where i would display the link something like http://www.mydomain.com/abc.doc but when the user clicks on this link i want then to be forced to login if not logged in. So the problem is how to protect any link like this? If I would have been redirecting a user to any ASP page then its very easy to check the session value and then either permit or deny, but how to check on a link which directly points to a doc file or zip file ? I hope i am not sounding like a fool :) Thanks a lot for all the help so far.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups