Upload if files from client PC or local network

Discussion in 'ASP .Net' started by =?Utf-8?B?U2lvYmhhbg==?=, Nov 1, 2005.

  1. Hi - I create a input box as follows:
    <INPUT id="inpJobDescEmpSpec" style="BORDER-RIGHT: gray thin solid;
    BORDER-TOP: gray thin solid; Z-INDEX: 181; LEFT: 232px; BORDER-LEFT: gray
    thin solid; WIDTH: 640px; BORDER-BOTTOM: gray thin solid; POSITION: absolute;
    TOP: 400px; HEIGHT: 22px" tabIndex="27" type="file" maxLength="250" size="87"
    name="inpJobDescEmpSpec" RunAt="Server">

    to allow the user to select a file which I want saved to a SQL Server
    database.

    On the save I then run this code to insert the document into the database:

    'only try and attach file if there is one specified
    Dim impersonationContext As
    System.Security.Principal.WindowsImpersonationContext
    Dim currentWindowsIdentity As
    System.Security.Principal.WindowsIdentity

    currentWindowsIdentity = CType(User.Identity,
    System.Security.Principal.WindowsIdentity)
    impersonationContext = currentWindowsIdentity.Impersonate()

    'Insert your code that runs under the security context of
    the authenticating user here.
    If Len(Trim(inpJobDescEmpSpec.Value)) <> 0 Then
    Dim fs As New System.IO.FileStream _
    (inpJobDescEmpSpec.Value,
    System.IO.FileMode.OpenOrCreate, _
    System.IO.FileAccess.Read)
    Dim MyData(fs.Length) As Byte
    fs.Read(MyData, 0, fs.Length)
    fs.Close()
    .JobDescEmpSpecDoc = MyData
    .UpdateDocument = True
    Else
    Dim MyData(0) As Byte
    .JobDescEmpSpecDoc = MyData
    .UpdateDocument = False
    End If
    impersonationContext.Undo()

    (where I am setting MyData to a byte property of my data class)

    This works perfectly fine in the development environment (my PC has Visual
    Studio and is the web server connectin to a SQL server database on out
    network.

    I can browse for and attach files with or network paths (C:\Folder\File.doc
    or \\Server\Share\Folder\File.doc)

    If I connect to the website on my PC from another PC the local drive upload
    works fine (C:\Folder\File.doc) but the network upload fails because
    somewhere along the way the backslashes are beibng removed so it is trying to
    access file \ServerShareFolderFile.doc

    Anyone any idea why this is?

    Thanks in advance
    Siobhan
     
    =?Utf-8?B?U2lvYmhhbg==?=, Nov 1, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?U2lvYmhhbg==?=

    intrader Guest

    On Tue, 01 Nov 2005 06:57:03 -0800, Siobhan wrote:

    > Hi - I create a input box as follows:
    > <INPUT id="inpJobDescEmpSpec" style="BORDER-RIGHT: gray thin solid;
    > BORDER-TOP: gray thin solid; Z-INDEX: 181; LEFT: 232px; BORDER-LEFT: gray
    > thin solid; WIDTH: 640px; BORDER-BOTTOM: gray thin solid; POSITION: absolute;
    > TOP: 400px; HEIGHT: 22px" tabIndex="27" type="file" maxLength="250" size="87"
    > name="inpJobDescEmpSpec" RunAt="Server">
    >
    > to allow the user to select a file which I want saved to a SQL Server
    > database.
    >
    > On the save I then run this code to insert the document into the database:
    >
    > 'only try and attach file if there is one specified
    > Dim impersonationContext As
    > System.Security.Principal.WindowsImpersonationContext
    > Dim currentWindowsIdentity As
    > System.Security.Principal.WindowsIdentity
    >
    > currentWindowsIdentity = CType(User.Identity,
    > System.Security.Principal.WindowsIdentity)
    > impersonationContext = currentWindowsIdentity.Impersonate()
    >
    > 'Insert your code that runs under the security context of
    > the authenticating user here.
    > If Len(Trim(inpJobDescEmpSpec.Value)) <> 0 Then
    > Dim fs As New System.IO.FileStream _
    > (inpJobDescEmpSpec.Value,
    > System.IO.FileMode.OpenOrCreate, _
    > System.IO.FileAccess.Read)
    > Dim MyData(fs.Length) As Byte
    > fs.Read(MyData, 0, fs.Length)
    > fs.Close()
    > .JobDescEmpSpecDoc = MyData
    > .UpdateDocument = True
    > Else
    > Dim MyData(0) As Byte
    > .JobDescEmpSpecDoc = MyData
    > .UpdateDocument = False
    > End If
    > impersonationContext.Undo()
    >
    > (where I am setting MyData to a byte property of my data class)
    >
    > This works perfectly fine in the development environment (my PC has Visual
    > Studio and is the web server connectin to a SQL server database on out
    > network.
    >
    > I can browse for and attach files with or network paths (C:\Folder\File.doc
    > or \\Server\Share\Folder\File.doc)
    >
    > If I connect to the website on my PC from another PC the local drive upload
    > works fine (C:\Folder\File.doc) but the network upload fails because
    > somewhere along the way the backslashes are beibng removed so it is trying to
    > access file \ServerShareFolderFile.doc
    >
    > Anyone any idea why this is?
    >
    > Thanks in advance
    > Siobhan

    The problem is that inside strings, the backslash is considered an escape
    to allow special characters. So you may use double slashes.
     
    intrader, Nov 1, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?U2lvYmhhbg==?=

    Bruce Barker Guest

    the problem is credentials forwarding. by default (and with ntlm impossible)
    its not allowed to forward user credentials from a second machine to a third
    (1 hop rule).

    when you are on your local box, iis and asp.net has a primatuy token and can
    talk to network resouces on other machines. if you connect to your pc from
    another, then iis and asp.net no longer have a primary token can can not use
    the token to talk to another resource.

    if you switch to kerberos and enable forwarding you will able to do what you
    want.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;810572

    -- bruce (sqlwork.com)




    "Siobhan" <> wrote in message
    news:...
    > Hi - I create a input box as follows:
    > <INPUT id="inpJobDescEmpSpec" style="BORDER-RIGHT: gray thin solid;
    > BORDER-TOP: gray thin solid; Z-INDEX: 181; LEFT: 232px; BORDER-LEFT: gray
    > thin solid; WIDTH: 640px; BORDER-BOTTOM: gray thin solid; POSITION:
    > absolute;
    > TOP: 400px; HEIGHT: 22px" tabIndex="27" type="file" maxLength="250"
    > size="87"
    > name="inpJobDescEmpSpec" RunAt="Server">
    >
    > to allow the user to select a file which I want saved to a SQL Server
    > database.
    >
    > On the save I then run this code to insert the document into the database:
    >
    > 'only try and attach file if there is one specified
    > Dim impersonationContext As
    > System.Security.Principal.WindowsImpersonationContext
    > Dim currentWindowsIdentity As
    > System.Security.Principal.WindowsIdentity
    >
    > currentWindowsIdentity = CType(User.Identity,
    > System.Security.Principal.WindowsIdentity)
    > impersonationContext = currentWindowsIdentity.Impersonate()
    >
    > 'Insert your code that runs under the security context of
    > the authenticating user here.
    > If Len(Trim(inpJobDescEmpSpec.Value)) <> 0 Then
    > Dim fs As New System.IO.FileStream _
    > (inpJobDescEmpSpec.Value,
    > System.IO.FileMode.OpenOrCreate, _
    > System.IO.FileAccess.Read)
    > Dim MyData(fs.Length) As Byte
    > fs.Read(MyData, 0, fs.Length)
    > fs.Close()
    > .JobDescEmpSpecDoc = MyData
    > .UpdateDocument = True
    > Else
    > Dim MyData(0) As Byte
    > .JobDescEmpSpecDoc = MyData
    > .UpdateDocument = False
    > End If
    > impersonationContext.Undo()
    >
    > (where I am setting MyData to a byte property of my data class)
    >
    > This works perfectly fine in the development environment (my PC has Visual
    > Studio and is the web server connectin to a SQL server database on out
    > network.
    >
    > I can browse for and attach files with or network paths
    > (C:\Folder\File.doc
    > or \\Server\Share\Folder\File.doc)
    >
    > If I connect to the website on my PC from another PC the local drive
    > upload
    > works fine (C:\Folder\File.doc) but the network upload fails because
    > somewhere along the way the backslashes are beibng removed so it is trying
    > to
    > access file \ServerShareFolderFile.doc
    >
    > Anyone any idea why this is?
    >
    > Thanks in advance
    > Siobhan
    >
     
    Bruce Barker, Nov 1, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=

    Upload/Download Files on Network File Server

    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=, Nov 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    400
    Tom Kaminski [MVP]
    Nov 19, 2004
  2. Tom Wells
    Replies:
    2
    Views:
    6,151
    Steve C. Orr [MVP, MCSD]
    Feb 2, 2005
  3. Replies:
    1
    Views:
    950
    Gabriel Genellina
    Nov 25, 2006
  4. Luqman
    Replies:
    2
    Views:
    516
    Luqman
    Sep 6, 2007
  5. Matt Hamilton

    Upload/Download Files on Network File Server

    Matt Hamilton, Nov 19, 2004, in forum: ASP .Net Security
    Replies:
    1
    Views:
    173
    Tom Kaminski [MVP]
    Nov 19, 2004
Loading...

Share This Page