> This tells me you have <identity impersonate=tru e /> in your web.config.
This says to impersonate on the thread during execution the identity IIS
is using. IUSR_machine in your case, given that you must be allowing
anonymous access.
Hmm...nope. No impersonation tag at all in my web.config file.
Ohh! You say it works once? This must mean you have the files left open?
Meaning, you've forgotten to close them, perhaps?
Maybe? That was my original thought. Here are the two key lines in my
function. The first creates the directory (if not created) and the second
saves the files.
system.IO.Direc tory.CreateDire ctory(savePath)
postedFile.Save As(savePath & strUploadFileNa me)
The first time the function runs, the directory is created, and the is
uplaoded. It's after that that I get denied access. Do I need to 'release'
the new directory I create and the files I upload?
Also, here's the full function if it is of any help:
------------------------------------------------------------------
Private Sub uploadFile(file ToUpload as System.web.Http PostedFile)
Dim saveVirtualPath As String = "/documents/forms/"
Dim savePath As String = Server.MapPath( saveVirtualPath )
if trim(secondaryC ategoryDirector y) <> ""
savePath = savePath & fixName(primary CategoryDirecto ry, "directory" )
& "\" & fixName(seconda ryCategoryDirec tory, "directory" )
else
savePath = savePath & fixName(primary CategoryDirecto ry, "directory" )
End If
if System.IO.Direc tory.Exists(sav ePath) then
'do nothing
else
response.Write( "<p>CREATIN G DIRECTORY</p>")
system.IO.Direc tory.CreateDire ctory(savePath)
End If
Dim strUploadFileNa me as string
'Make sure the path has a trailing slash
if Right( savePath, 1 ) <> "\" then savePath = savePath & "\"
Try
'Save some information from the upload and set up paths
Dim postedFile = fileToUpload 'fileUpload_DOC .PostedFile
Dim contentType As String = postedFile.Cont entType
Dim contentLength As Integer = postedFile.Cont entLength
strUploadFileNa me =
fixName(System. IO.Path.GetFile Name(PostedFile .FileName), "file")
'clean up the filename
strUploadFileNa me = fixName(strUplo adFileName, "file")
'save the file
postedFile.Save As(savePath & strUploadFileNa me)
Catch exc As system.Exceptio n
div_updateLog.V isible = true
lbl_updateLog.t ext = label_changeCon firmations.text &
"<p><b>Fail ed</b> to upload the file <i>" & strUploadFileNa me & ": " &
exc.InnerExcept ion.Message & _
"<br/>Please contact the system Administrator for help.</p>"
End Try
End Sub