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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lily86
    New Member
    • Aug 2008
    • 16

    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 :
    Code:
            Dim CurrentFileName As String
            CurrentFileName = FileUpload1.FileName
    
                    Dim CurrentPath As String = Server.MapPath("~/Img/")
    
            If FileUpload1.HasFile Then
                CurrentPath += CurrentFileName
    
                FileUpload1.SaveAs(CurrentPath)
                Response.Write("Upload the file already  !!!")
            Else
                Response.Write("Can not load the file !")
            End If
    error:

    Access to the path 'C:\Domains\bli ssfulbridalstud io.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.Unauthor izedAccessExcep tion: Access to the path 'C:\Domains\web page.com\httpdo cs\Img\Sunset.j pg' 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}\ASPNE T 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="tr ue"/>, the identity will be the anonymous user (typically IUSR_MACHINENAM E) 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.

    thanks!!!
    Last edited by Frinavale; Mar 9 '09, 02:06 PM. Reason: Added [code] tags: Please post code within [code] [/code] tags. Thanks.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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.



    -Frinny

    Comment

    • lily86
      New Member
      • Aug 2008
      • 16

      #3
      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!!!

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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?

        Comment

        • lily86
          New Member
          • Aug 2008
          • 16

          #5
          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....

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            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 ;)

            -Frinny

            Comment

            • lily86
              New Member
              • Aug 2008
              • 16

              #7
              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.

              Comment

              Working...