ASP.net Getting the error “Access to the path is denied.” while trying to upload files to my Windows Server 2008 R2 Web server

前端 未结 9 948
失恋的感觉
失恋的感觉 2020-11-28 04:51

I have an asp.net webapplication that uploads files to a specific folder on the Web server. locally everything works fine, but when I deploy the application to the Webserver

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 05:32

    If anyone stumbles across this as it is the first result in google,

    remember to specify the filename too in the SaveAs method.

    Won't work

    file_upload.PostedFile.SaveAs(Server.MapPath(SaveLocation));
    

    You need this:

    filename = Path.GetFileName(file_upload.PostedFile.FileName);
    file_upload.PostedFile.SaveAs(Server.MapPath(SaveLocation + "\\" + filename));
    

    I assumed the SaveAs method will automatically use the filename uploaded. Kept getting "Access denied" error. Not very descriptive of the actual problem

提交回复
热议问题