AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=336&pId=-1
Upload Files Using ASP.NET Impersonation and UNC Share
page
by Siva Manikanteswaran
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 82878/ 148

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


Product Spotlight
Product Spotlight 

©Copyright 1998-2020 ASPAlliance.com  |  Page Processed at 2020-09-23 5:52:54 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search