简体   繁体   English

ASP.NET MVC 4-将文件上传到服务器

[英]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. 拒绝访问路径“ D:\\ Hosting \\ 11029316 \\ html \\ gizmoblog \\ Content \\ Images \\ dpi.jpg”。

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? 有什么方法可以使用FTP流上载文件吗? Or even upload them using a URI to my website like http://www.weburl.com/uploads/filename ? 甚至使用URI将它们上传到我的网站,例如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). 在服务器上,IIS工作进程需要权限才能写入上载目录(出于安全考虑,默认情况下不允许这样做)。 See this link for more information 有关更多信息,请参见此链接。

http://support.microsoft.com/kb/979124 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. 为了回答您的其他问题,通过FTP流进行上传更复杂,并且没有必要,因为.NET框架包含了接受文件并保存文件所需的一切。

You might also be interested in trying out http://filepicker.io which offers a simple way to handle file management through an API. 您可能还想尝试http://filepicker.io ,它提供了一种通过API处理文件管理的简单方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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