Protect Non-ASP Files

From: Matt Rutherford (matt.l.rutherford@census.gov)
Date: 03/27/03


From: "Matt Rutherford" <matt.l.rutherford@census.gov>
Date: Thu, 27 Mar 2003 15:21:34 -0500


I am trying to restrict access to certain non-asp files, based on
information stored in a sql server database. I have tried setting up
roles/forms authentication to try and restrict access to these (PDF) files.
What I am trying to do with this, is load each file the user is able to see
into a "role". Then check to see which file link they have clicked on, then
compare to the roles they are allowed to see, and then allow it to be viewed
if the role exists. I'm sure there are better ways to do what I am trying
to do (please let me know if there is!!!), but my problem with this method,
is when the code gets to the line comparing the GetRedirectURL with the
IsInRole directive, the GetRedirectURL points to the last shown ASPX file,
not the PDF they clicked on... HELP??

Here is my web.config entries
<authentication mode="Forms"><forms name=".PROCAUTH"
loginUrl="http://localhost/proceduresdev/login.aspx"
timeout="30"></forms></authentication>

Here is my Application_Authenticate Request entries:
If Request.IsAuthenticated = True Then

Dim authName As String = User.Identity.Name

Dim cn As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("cnString"))

Dim cm As SqlCommand = New SqlCommand("spSELAllowedProc", cn)

Dim dr As SqlDataReader

Dim i As Integer = 1

FormsAuthentication.Initialize()

cn.Open()

cm.CommandType = CommandType.StoredProcedure

cm.Parameters.Add("@prmUserName", authName)

dr = cm.ExecuteReader

Dim arrRoles() As String

Do While dr.Read

ReDim Preserve arrRoles(i + 1)

arrRoles(i) = "http://localhost/proceduresdev/" & dr("FileLocation")

i += 1

Loop

cn.Close()

Dim objIdentity As GenericIdentity = New GenericIdentity(authName)

Context.User = New GenericPrincipal(objIdentity, arrRoles)

If Not User.IsInRole(FormsAuthentication.GetRedirectUrl(User.Identity.Name,
False)) Then

Response.Redirect("unauth.aspx")

End If

End If



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcad)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcsd)