Upload Files Using ASP.NET Impersonation and UNC Share
 
Published: 17 Dec 2003
Unedited - Community Contributed
Abstract
Uploading files with ASP.NET is easy, but permission problems can prevent uploads to network shares. This article describes the steps that are necessary to use ASP.NET to upload files to UNC shares.
by Siva Manikanteswaran
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 100369/ 236

Introduction

Download Sample

/download/336/uploadtest.zip

 

The Problem

 

When using upload functionality provided by Asp.net a common approach that is followed is to have the uploaded file in a virtual folder located in a remote machine other than the web server. The uploaded files needs to be stored in a remote location and mapped to the web server using a virtual folder pointing to a UNC share.

 

UNC Share

A directory shared in a remote machine can be accessed using UNC name such as \\RemoteMachineName\SharedFolder.

 

Virtual Folder

 

IIS provides a mechanism to point to the UNC share by creating a virtual folder with an alias pointing to UNC .Please note on 'Connect as user' specify just user name and password -- don’t give Remotemachinename\user.

 

 

Uploading using asp.net

 

Asp.net provides an easy upload feature which many of us have used .The problem happens when we try to upload a file using this virtual folder pointing to UNC share. Asp_wp account does not have access to the network resources by default.

Impersonation in ASP.NET

For asp.net to run in a user context you need to add

 

<identity impersonate="true" userName="UserX" password="Password123"/>

 

in the web.config to impersonate

 

 

Let us say that we have a Web server A and Fileserver B .We have mapped a virtual directory RemoteSharedFolder using IIS and pointing to share as 

\ \FileServerB\SharedFolder (no spaces)

 

We know for a fact that we need to impersonate because the aspnet_wp account would not have access to the folder and if we do not have a network user to access the resource follow the simple steps below:

 

  1. Create a local user account  in webserver say UserX with password Password123
  2. Create a local user account in File server with same name as above and same password UserX and Password123
  3. If you are using windows xp or windows .net server 2003 you don’t need do anything
  4. If you have Windows 2000 go to local security setting and browse to “User Rights assignment” and locate “Act as part of Operating System” policy. Double click and add “aspnet_wp” account
  5. Restart IIS service

 

You need to set permission for impersonated user for full control on C:\winnt\Microsoft.NET\Framework\v1.0.3705\Temporary ASP.NET Files so that the stream read from client as temporary stored in this folder till it is transferred to the Virtual Folder



User Comments

Title: dsf   
Name: dfd
Date: 7/9/2012 2:10:40 AM
Comment:
dfd
Title: unc share   
Name: Wesley
Date: 12/18/2011 12:01:28 PM
Comment:
Erro instalation Orbit Download: The drive Unc share you selected does not exist or is not accessible.pls tell me how to fix problem
Title: create folder on network PC   
Name: Sandeep
Date: 11/19/2010 12:18:06 AM
Comment:
I want to create network folder. See i have one web Server and one file server. So i want to create folder on file server using ASP.net, can anybody help..
Thanks in advance
Title: unc share   
Name: xayoulan nanthasack
Date: 10/16/2010 11:05:28 PM
Comment:
Erro instalation Orbit Download: The drive Unc share you selected does not exist or is not accessible.pls tell me how to fix problem
Title: Unc share   
Name: Antonio Landes
Date: 5/6/2010 8:12:30 PM
Comment:
Erro instalation Orbit Download: The drive Unc share you selected does not exist or is not accessible.
l.andes@hotmail.com
Title: MR   
Name: Yah hneh
Date: 4/14/2010 4:36:16 AM
Comment:
I tried, but cudnt get it right.
Title: How to write/modify to network files?   
Name: Prasad
Date: 2/18/2010 6:02:27 AM
Comment:
Hi, this code works when we want to "read" network files.

What needs to be done if I want to "write/modify" these network files?

Thanks
Prasad
Title: sry!!!!   
Name: hrithik
Date: 12/2/2009 9:08:31 AM
Comment:
your approach is fyn bt can you explain wht to do when the folder we tend to share is on other network drive and the working folder is in other...
wht 2 do in this case??
have any ans then do share.......
Title: verify if file exists on network folder   
Name: riyaz
Date: 7/9/2009 4:01:33 AM
Comment:
\
\
\
\
Title: verify if file exists on network folder   
Name: riyaz
Date: 7/9/2009 3:54:36 AM
Comment:
\
\
\
\
\
\
\
Title: problem while only reading / downloading the file from remote server using impersonation   
Name: Pallav
Date: 6/9/2009 4:33:36 AM
Comment:
Hi I am able to upload files to one remote file share using impersonation of .net but i am not able to read / download that file using the same function. It is asking me to enter again user name / pwd. Please help me whether i need to change some settings at file share side or not
Title: Loading file from webserver is very slow?   
Name: mH
Date: 11/20/2008 3:03:42 AM
Comment:
When directory shared is bigger. Loading file from webserver is very slow. How to increasing the loading rate
Title: A better way   
Name: EMG
Date: 11/18/2008 9:32:48 AM
Comment:
Set the identity in the app pool to a use a service account and then add that service account to the local IIS_WPG group. Recycle pool...viola!
Title: Good Explanatory article.   
Name: Asif Syed
Date: 10/17/2008 8:09:47 AM
Comment:
a very good and discriptive article on web & file server concept. I was struggled for this concept for over two days as roaming on net walls, it's my luck i caught this link.
Thank you very much.
Title: Question?   
Name: gsk
Date: 8/12/2008 2:21:41 PM
Comment:
The solution is good? Thanks...
But what if i wanted to use the same approach, but without setting the impersonate to true then how to proceed any idea?

Thanks,
gsk
Title: Thank you   
Name: VietOri
Date: 7/4/2008 6:18:20 AM
Comment:
It's solution for upload in distributed server
Title: Great work...   
Name: Manpreet
Date: 5/29/2008 4:19:43 AM
Comment:
I was trying to do this for last two days. I searched a lot on internet but nobody mention about the permission on the temporary folder.and that was the thing i was missing..thanks..
Title: Resolving Network Path   
Name: HR
Date: 5/20/2008 1:28:10 AM
Comment:
\
\
Title: uploading files   
Name: nilesh
Date: 4/9/2008 7:01:47 AM
Comment:
tell me how i can upload file in domain using asp.net(vb.net)
Title: Unable to store file in network drive   
Name: Rehan
Date: 12/12/2007 8:10:52 AM
Comment:
\
\
\
\
Title: Access denied!! ...sigh...   
Name: Leon Pretorius
Date: 9/3/2007 5:15:53 PM
Comment:
I gave 2 specific users rights on the server. I created a roaming profile and a network drive. The profile worls fine but the 2 specific users cant save to a folder on the mapped drive (mining, which is all they are alowed to use anyway) Now they can read but cannot write to this folder but they have full rights on it. This has been a head ache ever since i did the server installation. HELP PLZ!!!

Please if possible reply on my mail : lspretorius@gmail.com

Kind Regards

Leon
Management
..IT Company
Title: URL   
Name: Haresh V
Date: 7/4/2007 9:36:20 AM
Comment:
Sorry, I thought url entry will be shown. Please note my url: http://admin.ojeez.com/upload.aspx
Title: Not able to access the path   
Name: Haresh V
Date: 7/4/2007 9:35:03 AM
Comment:
Mr. Shiva,

Thanks for this article. I tried the same as you mnetioned above. But its giving me the error: Access to the path is denied.

Would you be so kind to take a look at my url and can you please guide me where I am missing the configuration?

Thanks,

Haresh
Title: Not able to access the path   
Name: Haresh
Date: 7/4/2007 9:33:23 AM
Comment:
\
\
\
\S
Title: Very helpful.. thank you so much   
Name: Cindy Chan
Date: 6/26/2007 5:43:55 AM
Comment:
Our team have been searching for the solution for so long and finally your article had save our life!
Title: Programmer   
Name: Spark
Date: 6/12/2007 3:59:58 PM
Comment:
Excellent. Thank you very much.
Title: Windows 2000 solution   
Name: Author
Date: 4/23/2007 12:49:28 AM
Comment:
I meant you dont do need anything if you have windows 2003 or xp.The step was to be done only for windows 2000
Title: Requirement of Help in developing of Remote File Sharing   
Name: Abid Mahmood
Date: 10/17/2006 1:26:25 AM
Comment:
Dear Sir;
I appreciate about your article relating to uploading of file on net.

Respected Sir, i am student of 8TH Semester of BCS. i choose my final Project "Remote File Sharing".I want to develop it using .NET Framework by using any language of it.
and i need Help relating to it.
kindly send me article related to my project or help me.

Best Regard.
ABID MAHMOOD
BCSS03A131
saith_abid131@yahoo.com
Title: Still not working   
Name: Thiru
Date: 7/6/2006 9:51:54 AM
Comment:
I tried out the steps that you have mentioned but still iam not able to read write to file system. i get an access denied message.

i created a local user as mentioned and gave it limited rights (followed this link also http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT01.asp)

but still it doesnt work.....but if i use my domain user id and password then it works....but i dont want to use them....

pls help
Title: how to use unc in code   
Name: ramesh
Date: 6/7/2006 7:24:58 AM
Comment:
hello sir u have given clear explination but how we can use unc share in our programme
Title: Configuration error   
Name: Pothiraja
Date: 6/6/2006 1:18:31 AM
Comment:
Dear friend,
I'm also trying to map the network file to the web server. As per your instructions.
I created the username same as you given(both Fileserver/Web server).
But i got the error message. Configuration error. Error message
The located assembly's manifest definition with name 'Assemblyname' does not match the assembly reference.

could you please help me out. Where i'm mistaking.
Title: Good Tips   
Name: Santhosh Kumar
Date: 5/24/2006 10:36:19 AM
Comment:
I tried this article. And my web application is wroking fine.

Thanking You

Santhosh Kumar

santhoshvnath@yahoo.com
Title: thank you   
Name: NKT
Date: 3/10/2006 10:26:11 AM
Comment:
Great article. Thank you. The problem was exactly my problem. It works, thank you again
Title: Better Link   
Name: Jay Dubal
Date: 2/14/2006 2:28:48 PM
Comment:
Hello,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT01.asp

Thanks,
Jay Dubal
Tech Lead
Gateway Technolabs Pvt. Ltd.
Title: clarification   
Name: Siva
Date: 9/30/2005 10:25:16 AM
Comment:
see point 4

If you have Windows 2000 go to local security setting and browse to “User Rights assignment” and locate “Act as part of Operating System” policy. Double click and add “aspnet_wp” account
Title: re   
Name: vodka
Date: 9/30/2005 9:23:26 AM
Comment:
If you are using windows xp or windows .net server 2003 you don’t need do anything


what do u mean with that?

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 4/23/2014 10:21:58 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search