简体   繁体   中英

ASP.NET MVC 4 - Uploading files to a server

I'm trying to upload a file to my website using a method I found on the net. When i upload files in debug mode, it works fine, but when I try to upload on my website, I get this error.

Access to the path 'D:\\Hosting\\11029316\\html\\gizmoblog\\Content\\Images\\dpi.jpg' is denied.

This is the method I'm using to upload files.

public ActionResult UpdateLogo(HttpPostedFileBase SiteLogo)
{
   if (SiteLogo.ContentLength > 0)
   {
       var fileName = Path.GetFileName(SiteLogo.FileName);
       var path = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
       SiteLogo.SaveAs(path);
   }
}

Is there a way I can upload the file using a FTP stream? Or even upload them using a URI to my website like http://www.weburl.com/uploads/filename ? Really need help guys..

This is a permissions issue on your server. On your local machine you are running under the context of your current user, which allows you to write to your disk. On the server, the IIS worker process needs permission to write to the uploads directory (it is not allowed by default for security). See this link for more information

http://support.microsoft.com/kb/979124

To answer your other questions, uploading via an FTP stream is more complex and not necessary since the .NET framework includes everything you need to accept a file upload and save it.

You might also be interested in trying out http://filepicker.io which offers a simple way to handle file management through an API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM