суббота, 8 ноября 2008 г.

Upload file - acces denied - ASP.NET

Problem:
It shows error during uploading the file :

Access to the path 'C:\Inetpub\vhosts\mysite.com\httpdocs\inbox\picture.jpg' is denied.

the code is like this:

string filename=File1.PostedFile.FileName;

try
{
File1.PostedFile.SaveAs(Server.MapPath(filename));
}


solution:

Grant ASP.NET write access to the folder:
right click the actual folder in file explorer and allow EVERYONE to write to this folder.


Description:

ASP.NET is not authorized so save files in temp folder (defined by tempPath parameter). Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_{MACHINENAME}) or the authenticated request user.

To grant ASPNET (in the case of IIS 5) or NETWORK SERVICE (in the case of IIS 6) or other needed account write access to a folder, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the needed account, and check the boxes for the desired access.

references:

How to upload a file to a Web server in ASP.NET by using Visual Basic .NET:
http://support.microsoft.com/default.aspx?scid=kb;en-us;323245

ASP.NET Impersonation:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsent7/html/vxconimpersonation.asp

Комментариев нет: