在asp.net Web上传大文件 [英] upload large file in asp.net Web

查看:97
本文介绍了在asp.net Web上传大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家

i需要在我的网站上上传大文件(<200 MB)。

i改变了我的网页配置:



hi experts
i need to upload large file in my website ( < 200 MB ).
i changed my web config:

<system.web>
     <httpRuntime maxRequestLength="200000" executionTimeout="3600"requestValidationMode="2.0"/>

......
</system.web>











and

<system.webServer>
   <security>
       <requestFiltering>
           <requestLimits maxAllowedContentLength="200000000"/>
        </requestFiltering>
   </security>
</system.webServer>





在本地主机中它是正确的但在服务器中我收到此错误:



404 - 找不到文件或目录。

您要查找的资源可能已被删除,名称已更改或暂时不可用。



提前感谢



in local host it is correct but in server i got this error:

404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

thanks in advance

推荐答案

我同意迈蒙尼德,因为错误信息与路径问题有关你有。



首先,尝试上传一个小文本文件(5或10 kb),如果失败则路径问题。没有看到你的代码,我不能告诉你更多。



这里有一些修复链接给你



ASP.NET中的大文件上传 [ ^ ]

如何使用ASP.Net,C#将大型文件/ blob上传到Azure存储[ ^ ]

处理ASP.Net上传文件大小问题 [ ^ ]
I agree with Maimonides, it's related to path issues because of the error message which you got.

First, try to upload a small textfile(5 or 10 kb), if it fails then path is issue. Without seeing your code, I can't tell you more.

Here some fix links for you

Large file uploads in ASP.NET[^]
How to upload large size file/blob to azure storage using ASP.Net,C#[^]
Dealing With the ASP.Net Upload File Size Problem[^]


如果相同的代码在本地工作,但在托管服务器上不起作用,那么它不是代码的问题。只需检查配置;特别是文件的路径。可能是您要提供要上载的文件的绝对路径,并且该路径不存在。你提到的错误是指路径问题。
If the same code works on local but doesn't work on hosting server, then its not the issue with the code. Just check the configuration; especially the path of the file. May be you are giving the absolute path of the file to be uploaded and that path is not existing. The error you have mentioned refers to the issue of path.


我的代码:



its my code:

if (oHttpPostedFile.ContentLength == 0)
                            {
                                //Your picture file was not successfully uploaded!
                                throw (new            MyWebApplication.ApplicationException(Resources.Messages.ErrorMessage010));
                            }
                            else
                            {
                                var realFileName = Path.GetFileName(strPathName);
                                var userfileid = 0;
                                if (extension != null)
                                {
                                    userfileid = InsertFileInDb(userID, realFileName, address, extension.ToUpper(), oHttpPostedFile.ContentLength / 1024, 0);
                                }
                                var writePathName = HttpContext.Current.Server.MapPath(string.Format("~/UserFiles/{0}/{1}", userID, userfileid + "-" + realFileName));
                                oHttpPostedFile.SaveAs(writePathName);

                                var backupDirectory = HttpContext.Current.Server.MapPath(string.Format("~/UserFiles/{0}/BackUp", userID));
                                if (Directory.Exists(backupDirectory) == false)
                                    Directory.CreateDirectory(backupDirectory);
                                oHttpPostedFile.SaveAs(backupDirectory + "/" + userfileid + "-" + realFileName);

                                return strFileName;

                            }



它与路径问题无关,因为我可以上传小文件,但是当我更改我的网络配置以上传大文件时,大文件我收到了这个错误。

您怎么看?它与以下内容无关:


it's not related to path issues because i can upload small file but when i change my web config to upload large file, in large file i got this error.
what do you think? its not related to :

<system.webServer>
   <security>
       <requestFiltering>
           <requestLimits maxAllowedContentLength="200000000"/>
        </requestFiltering>
   </security>
</system.webServer>





非常感谢你。



thank you so much.


这篇关于在asp.net Web上传大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆