470,641 Members | 2,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

upload image to the server file error.....

i'm using vs.net 2003.... i want to let the user upload images and i want to save the image to my web server file to convenient i display the images on other pages.... but i'm having a problem when i try to save the images file to my we b server side....
here is my code :
Expand|Select|Wrap|Line Numbers
  1.         Dim CurrentFileName As String
  2.         CurrentFileName = FileUpload1.FileName
  4.                 Dim CurrentPath As String = Server.MapPath("~/Img/")
  6.         If FileUpload1.HasFile Then
  7.             CurrentPath += CurrentFileName
  9.             FileUpload1.SaveAs(CurrentPath)
  10.             Response.Write("Upload the file already  !!!")
  11.         Else
  12.             Response.Write("Can not load the file !")
  13.         End If

Access to the path 'C:\Domains\blissfulbridalstudio.com\httpdocs\Img\ Sunset.jpg' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\Domains\webpage.com\httpdocs\Img\Sunset.jpg' is denied.

ASP.NET is not authorized to access the requested resource. 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 <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
Mar 9 '09 #1
6 3623
9,735 Expert Mod 8TB
ASP.NET web applications have do not have permission to access files on the server by default. This is for security reasons.

If you want to be able to access a file/folder through your ASP.NET application you need to make sure that it has permissions set to allow it to do so.

There are a couple of ways to fix this problem, the first is to set the permissions on your folder to allow the ASPNET user permission to access the folder.

The second is to use impersonation.

Mar 9 '09 #2
Frinny, thanks for your reply... but i not really know how to do.... i don't know how to set the permission for ASP.NET application at server....can you tell me the step?? thanks you very much!!!
Mar 11 '09 #3
9,735 Expert Mod 8TB
Well the first step would be to add a folder to your project where you will store the photos....

Have you published your application onto a web server?
What version of IIS are you running?
Or are you just using the Visual Studio virtual server?
Mar 11 '09 #4
ya, i already post my application to web server....when i create new folder at the server there still have the same error.... i need to make some setting at my folder?
thanks you....
Mar 11 '09 #5
9,735 Expert Mod 8TB
What version operating system is your website hosted on?
What type of authentication are you using?

If you are using Windows XP, or Windows Server 2003 and if you haven't set up any special authentication, then your web application is run under the ASPNET user account (by default). Therefore, you need to give permissions to the ASPNET user account:
  • right click on the folder where the images will be stored,
  • click properties,
  • click the security tab,
  • if not there already, add ASP.NET Machine account (ASPNET),
  • give Read/Write permissions to the ASPNET account on the folder

If you're using Vista or Windows 2008, it's a different account....I can't remember what they renamed it to so you'll have to look it up ;)

Mar 11 '09 #6
thanks ya Frinavale, i already get the solutions.... is the permission problem....i compare with those file that can upload the photo then i change my permission same with the file.
Mar 19 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by dave | last post: by
1 post views Thread by John Thompson | last post: by
reply views Thread by SEMIH DEMIR | last post: by
9 posts views Thread by Wayne Smith | last post: by
1 post views Thread by Korara | last post: by
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.