Upload if files from client PC or local network

G

Guest

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
 
I

intrader

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.
 
B

Bruce Barker

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,516
Members
44,983
Latest member
BuyX10BoostKeto

Latest Threads

Top