Hi friends,
My question is...
I was Created asp.net application using asp 2005 and code behind file as the C#.net with IIS 6
Then I host my web application on internet in IIS 6 server...
There is the page,using this i can upload file[image files] to internet...[by using file uploader] when i upload some file to my remote machine there is the exception occur like that

System.UnauthorizedAccessException: Access to the path 'D:\inetpub\vhosts\foxads.lk\httpdocs\foX\mainImage\314.jpg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at System.Web.UI.WebControls.FileUpload.SaveAs(String filename) at createAd1.addMainImage(Int32 AdId)

Wht am i doo please help me...:D
my c# source code is...

mainImage.SaveAs(Server .MapPath ("~/mainImage/myImage.jpg"));

thanks.......

Well, from first glance 1 of 2 things is happening here:

  1. You don't have rights set up correctly to access that directory via your webserver
  2. A file already exists by that name in that directory and the rights haven't been set correctly to allow an overwrite of the file

One way to test the 2nd possibility is to try uploading a different file name after confirming that it doesn't already exist in the target directory and see if you get the same error.

Alternately, check your IIS settings on the remote host to confirm that a) the working directory you intended is properly set and b) the permissions are set in such a way as to allow access (read/write/modify) to the required directory in the method you're using.

Hope this helps :) Please remember to mark the thread solved once your issue is resolved.

Hi,

When you run an ASP.NET application from VS 2005 (without using IIS), it runs under your account's security context. Since you may have read/write access to the folder, you are able to upload files to that folder from your application.

But When you deploy and run an ASP.NET application from IIS, It runs under ASPNET account in Windows XP and NT AUTHORITY\Network Service account in Windows 2003.

You need to provide read/write access to 'mainImage' folder to NT AUTHORITY\Network Service account, so that you can save file to that folder from your asp.net application.

commented: Good catch! :) +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.