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. access to network shared

access to network shared

Scheduled Pinned Locked Moved ASP.NET
helpsysadminsecurityquestion
12 Posts 2 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.
  • M Offline
    M Offline
    mayl
    wrote on last edited by
    #1

    Hi I'm trying to do a directory listing on a network shared (\\machinename\sharedfolder) which granted everyone read/list access. I have my authentication mode set to Window and identity impersonate = false (our standard) in the web.config file. I tried to use the below code. However, I'm getting "Login Failure: unknown user name or bad password". If I just add a hyperlink to a file under that share, it opens the file with no problem. Dim impersonationContext As WindowsImpersonationContext Dim currentWindowsIdentity As WindowsIdentity = CType(User.Identity, WindowsIdentity) impersonationContext = currentWindowsIdentity.Impersonate() Dim ds As New DataSet Dim dt As New DataTable("Files") Dim dr As DataRow dt.Columns.Add("Filename", GetType(String)) Dim objDirInfo As New DirectoryInfo("\\machinename\sharedfolder\") Dim fi As FileInfo Dim fileInfos() As FileInfo fileInfos = objDirInfo.GetFiles("*.*") Dim i As Integer = fileInfos.Length If i > 0 Then For Each fi In fileInfos dr = dt.NewRow() dr(0) = fi.Name dt.Rows.Add(dr) Next End If ds.Tables.Add(dt) Me.DataGrid1.DataSource = ds Me.DataGrid1.DataBind() impersonationContext.Undo() Can anyone help? thank you

    I 1 Reply Last reply
    0
    • M mayl

      Hi I'm trying to do a directory listing on a network shared (\\machinename\sharedfolder) which granted everyone read/list access. I have my authentication mode set to Window and identity impersonate = false (our standard) in the web.config file. I tried to use the below code. However, I'm getting "Login Failure: unknown user name or bad password". If I just add a hyperlink to a file under that share, it opens the file with no problem. Dim impersonationContext As WindowsImpersonationContext Dim currentWindowsIdentity As WindowsIdentity = CType(User.Identity, WindowsIdentity) impersonationContext = currentWindowsIdentity.Impersonate() Dim ds As New DataSet Dim dt As New DataTable("Files") Dim dr As DataRow dt.Columns.Add("Filename", GetType(String)) Dim objDirInfo As New DirectoryInfo("\\machinename\sharedfolder\") Dim fi As FileInfo Dim fileInfos() As FileInfo fileInfos = objDirInfo.GetFiles("*.*") Dim i As Integer = fileInfos.Length If i > 0 Then For Each fi In fileInfos dr = dt.NewRow() dr(0) = fi.Name dt.Rows.Add(dr) Next End If ds.Tables.Add(dt) Me.DataGrid1.DataSource = ds Me.DataGrid1.DataBind() impersonationContext.Undo() Can anyone help? thank you

      I Offline
      I Offline
      Ista
      wrote on last edited by
      #2

      I doubt your security token being return is valid 1 line of code equals many bugs. So don't write any!!

      M 1 Reply Last reply
      0
      • I Ista

        I doubt your security token being return is valid 1 line of code equals many bugs. So don't write any!!

        M Offline
        M Offline
        mayl
        wrote on last edited by
        #3

        thanks for your reply. However, I'm not quite sure what you mean. I'm new at asp.net. How do I do file listing on a network shared then? thank you

        I 1 Reply Last reply
        0
        • M mayl

          thanks for your reply. However, I'm not quite sure what you mean. I'm new at asp.net. How do I do file listing on a network shared then? thank you

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #4

          this is a good example of impersonation http://www.codeproject.com/csharp/cpimpersonation1.asp[^] 1 line of code equals many bugs. So don't write any!!

          M 2 Replies Last reply
          0
          • I Ista

            this is a good example of impersonation http://www.codeproject.com/csharp/cpimpersonation1.asp[^] 1 line of code equals many bugs. So don't write any!!

            M Offline
            M Offline
            mayl
            wrote on last edited by
            #5

            Hi I'm getting access to path \\computername\sharedfolder is denied. thanks

            1 Reply Last reply
            0
            • I Ista

              this is a good example of impersonation http://www.codeproject.com/csharp/cpimpersonation1.asp[^] 1 line of code equals many bugs. So don't write any!!

              M Offline
              M Offline
              mayl
              wrote on last edited by
              #6

              Although I get "access to path is denied" message, I can create a link to open a file under that share directly. ( Any ideas?

              I 1 Reply Last reply
              0
              • M mayl

                Although I get "access to path is denied" message, I can create a link to open a file under that share directly. ( Any ideas?

                I Offline
                I Offline
                Ista
                wrote on last edited by
                #7

                check the user that is set to "run as" inside the IIS console 1 line of code equals many bugs. So don't write any!!

                M 1 Reply Last reply
                0
                • I Ista

                  check the user that is set to "run as" inside the IIS console 1 line of code equals many bugs. So don't write any!!

                  M Offline
                  M Offline
                  mayl
                  wrote on last edited by
                  #8

                  Hi Are you referring to the Authentication Methods? I checked Integrated Windows authentication" only. thank you for being so repsonsive.

                  I 1 Reply Last reply
                  0
                  • M mayl

                    Hi Are you referring to the Authentication Methods? I checked Integrated Windows authentication" only. thank you for being so repsonsive.

                    I Offline
                    I Offline
                    Ista
                    wrote on last edited by
                    #9

                    no. In my last posts I staed you should check your user under IIS. So go to start->control panel->Admin->IIS right click properties on your web site and check that user. Odds are he doesn't have permissions to access that folder 1 line of code equals many bugs. So don't write any!!

                    M 1 Reply Last reply
                    0
                    • I Ista

                      no. In my last posts I staed you should check your user under IIS. So go to start->control panel->Admin->IIS right click properties on your web site and check that user. Odds are he doesn't have permissions to access that folder 1 line of code equals many bugs. So don't write any!!

                      M Offline
                      M Offline
                      mayl
                      wrote on last edited by
                      #10

                      when I right click properties on my IIS website, I get the Properties pop up and I see the -Virtual Directory tab -Documents tab -Directory Security tab -HTTP Headers tab -Custom Errors tab Where do I check the User? thanks

                      I 1 Reply Last reply
                      0
                      • M mayl

                        when I right click properties on my IIS website, I get the Properties pop up and I see the -Virtual Directory tab -Documents tab -Directory Security tab -HTTP Headers tab -Custom Errors tab Where do I check the User? thanks

                        I Offline
                        I Offline
                        Ista
                        wrote on last edited by
                        #11

                        DirectorySecurity -> click "Edit" button That will tell you the user your looking for. then armed with that information, right click on the network share and give that user permission to do what should be done. I don't memorize the tabs. So I usually just click on them until I find the right one. You will start using this constantly. 1 line of code equals many bugs. So don't write any!!

                        M 1 Reply Last reply
                        0
                        • I Ista

                          DirectorySecurity -> click "Edit" button That will tell you the user your looking for. then armed with that information, right click on the network share and give that user permission to do what should be done. I don't memorize the tabs. So I usually just click on them until I find the right one. You will start using this constantly. 1 line of code equals many bugs. So don't write any!!

                          M Offline
                          M Offline
                          mayl
                          wrote on last edited by
                          #12

                          Hi Ista, I think I got the answer to my issue. I used the LogonUsr api and it works. Thank you for helps.

                          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