473,799 Members | 2,723 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\AS PNET
Unmanaged Thread Identity: mycomputerid\IU SR_mycomputerid
Client Identity (HttpContext.Us er): [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 2085
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.

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\AS PNET
Unmanaged Thread Identity: mycomputerid\IU SR_mycomputerid
Client Identity (HttpContext.Us er): [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=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
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
15465
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 shows all current backups, and restores the selected one with one click...
9
10906
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 the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
1
3963
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 this web application, I have search page that utilizes the Windows Indexing Service (MSIDXS provider). For reasons I'm not aware of at this time, setting <identity impersonation="true" /> in the web.config causes an error whenever you try to search.
4
1417
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 windows authentication via IIS. Some pages within my web application access a MS SQL Server database hosted on a separate server. The database connection string is set to use a trusted connection. Now the problem is, that sometimes the user's...
6
1982
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 or user group 'mymachinename\ASPNET not found'. This all works however, if the databse server is my local machine. So the question then becomes, how can I give this user privileges to connect to this remote database server?
6
2447
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" password="123abc" /> in web.config, but I cannot browse the folder by browse button (i.e. <INPUT type=file runat="server") when the folder just allow access by user test.
11
2855
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
1241
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 windows-user account. That account does not have too much rights (just access to the application directory and the windows\Microsoft.Net directory). In Web.config I have also set <identity impersonate="true" userName=<myUser> password=<myPWD>/> ...
3
2624
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 2003 Server, ServerA, running as a Web Server that uses ASP.NET. The default.aspx file tries to access a file in a share on another computer, ServerB. ServerA and ServerB are on the same domain and are both running Windows 2003 Server.
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10237
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.