473,498 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using impersonation to allow writing to server directory?

I'm struggling with an odd permissions problem I have with one of my
functions. It takes a file, writes a directory, and then uploads some files
to it. This works. Once. Any subsequent attempt and writing new files to the
created directory results in an access denied error.

Thanks to a script by Keith Brown, I was able to determine who my
application was running as:
================================================== ====

Unmanaged Process Identity: mycomputerid\ASPNET
Unmanaged Thread Identity: mycomputerid\IUSR_mycomputerid
Client Identity (HttpContext.User): [anonymous]

================================================== ====


The root folder I am writing too (and any child folder created by my script)
has the ASPNET user given full permissions. I don't have IUSER set up on any
of these folders.

Should I have IUSER set up with write permissions? Or is this where I should
consider using impersonation, and set up a new user just for writing to this
one parent directory? The one catch is that impersonation seems to be at an
application level...not an individual function level.

-Darrel
Nov 19 '05 #1
6 2057
This tells me you have <identity impersonate=true /> 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.

Ohh! You say it works once? This must mean you have the files left open?
Meaning, you've forgotten to close them, perhaps?

-Brock
DevelopMentor
http://staff.develop.com/ballen
I'm struggling with an odd permissions problem I have with one of my
functions. It takes a file, writes a directory, and then uploads some
files to it. This works. Once. Any subsequent attempt and writing new
files to the created directory results in an access denied error.

Thanks to a script by Keith Brown, I was able to determine who my
application was running as:
================================================== ====

Unmanaged Process Identity: mycomputerid\ASPNET
Unmanaged Thread Identity: mycomputerid\IUSR_mycomputerid
Client Identity (HttpContext.User): [anonymous]
================================================== ====

The root folder I am writing too (and any child folder created by my
script) has the ASPNET user given full permissions. I don't have IUSER
set up on any of these folders.

Should I have IUSER set up with write permissions? Or is this where I
should consider using impersonation, and set up a new user just for
writing to this one parent directory? The one catch is that
impersonation seems to be at an application level...not an individual
function level.

-Darrel


Nov 19 '05 #2
> This tells me you have <identity impersonate=true /> 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.Directory.CreateDirectory(savePath)
postedFile.SaveAs(savePath & strUploadFileName)
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(fileToUpload as System.web.HttpPostedFile)
Dim saveVirtualPath As String = "/documents/forms/"
Dim savePath As String = Server.MapPath(saveVirtualPath)

if trim(secondaryCategoryDirectory) <> ""
savePath = savePath & fixName(primaryCategoryDirectory, "directory")
& "\" & fixName(secondaryCategoryDirectory, "directory")
else
savePath = savePath & fixName(primaryCategoryDirectory, "directory")
End If

if System.IO.Directory.Exists(savePath) then
'do nothing
else
response.Write("<p>CREATING DIRECTORY</p>")
system.IO.Directory.CreateDirectory(savePath)
End If

Dim strUploadFileName 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.ContentType
Dim contentLength As Integer = postedFile.ContentLength
strUploadFileName =
fixName(System.IO.Path.GetFileName(PostedFile.File Name), "file")

'clean up the filename
strUploadFileName = fixName(strUploadFileName, "file")

'save the file
postedFile.SaveAs(savePath & strUploadFileName)

Catch exc As system.Exception
div_updateLog.Visible = true
lbl_updateLog.text = label_changeConfirmations.text &
"<p><b>Failed</b> to upload the file <i>" & strUploadFileName & ": " &
exc.InnerException.Message & _
"<br/>Please contact the system Administrator for help.</p>"
End Try
End Sub
Nov 19 '05 #3
> Hmm, perhaps in a parent web.config?

Nope.
I'd debug just to make sure your filenames are correct.
Yep. I've done all that...response.writing every single string out.

Also, I can upload fine to the root directory. It's only ones that my
application creates that the access denied error happens.
Also, consider using
Path.Combine to merge the directory name and the filename.


I'll try that!

Otherwise, I think I'm going to set up a new user 'formUploads' and then
have my application run as that user via impersonation. Does that sound like
a valid solution?
Nov 19 '05 #4
> Otherwise, I think I'm going to set up a new user 'formUploads' and
then have my application run as that user via impersonation. Does that
sound like a valid solution?


Well, it's still hard to tell what the exact problem is. I'd not want to
give advice without knowing for sure.

-Brock
DevelopMentor
http://staff.develop.com/ballen

Nov 19 '05 #5
> Well, it's still hard to tell what the exact problem is.

Hence my predicament. ;o)

-Darrel
Nov 19 '05 #6
Heh... sorry that my last post wasn't too helpful :(

-Brock
DevelopMentor
http://staff.develop.com/ballen
Well, it's still hard to tell what the exact problem is.

Hence my predicament. ;o)

-Darrel


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
15447
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button, click and its done... The a restore option, that...
9
10857
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
1
3943
by: techfuzz | last post by:
I'm posting my problem experience and solution I found here for other ASP.NET developers. I have a web application that uses Forms Authentication with Active Directory to control access. In...
4
1404
by: Thomas | last post by:
Hi all! I have an asp.net web application that is configured for dynamic impersonation via web.config (identity impersonate=true). The corresponding virtual directory is protected by integrated...
6
1962
by: Marina | last post by:
Hi, I would like to give the ASPNET process that is running on my machine permission to connect to a sql server database that is on another machine. When I try to do this it says: 'Windows NT user...
6
2424
by: Philip Lee | last post by:
Dear all, How can I access files in remote file server through my ASP.NET application only, but deny all other users? I have added <identity impersonate="true" userName="test"...
11
2821
by: Phil | last post by:
Hi, I've currently setup a local user as described in: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnne...
1
1218
by: Matthias Wohlmann | last post by:
Hi, I've got an ASP.NET Web-Application written in C#. In IIS 6.0 (Windows Server 2003) I have set the application to allow anonymous access, but instead of the default user I use an own...
3
2606
by: Jay-nospam | last post by:
Hi there, I am having trouble getting an ASP.NET web application to connect to another computer and passing the proper credentials and I hope someone can help me. I have a stand-alone Windows...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4584
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.