HttpPostedFileBase status in asp.net mvc

本文关键字:net mvc asp in status HttpPostedFileBase | 更新日期: 2023-09-27 17:56:38

asp.net mvc 操作采用 HttpPostedFileBase 参数:

public ActionResult Save(HttpPostedFileBase file)
{
    //Q1: at the start of this action method, what's the status of this file? 
    //UploadCompleted or Uploading or something else?
    //Q2: where is the file stored? memory or a temp file?
    if (answer of Q1 is Uploading)
    {
        //Q3a: what happens if file.SaveAs is invoked? 
        //block the current thread until the file is uploaded?
    }
    else if (answer if Q1 is UploadCompleted)
    {
        //Q3b: which means the developer can do nothing before the file is uploaded?
        //if the business logic limits the size of the file(e.g. <= 5MB), how can we
        //prevent evil-intended uploading?
    }
}

Q4 这里:我想记录此请求的总时间,当用户开始上传文件时,计时器启动。当用户完成上传文件(或我的Save操作完成)时,计时器结束。我如何知道用户何时开始上传?

HttpPostedFileBase status in asp.net mvc

首先,看看这个问题的基础知识: 文件上传 ASP.NET MVC 3.0

Q1 :文件完全可用后将调用该操作。

Q2 : 从 msdn : http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.aspx

服务器内存中为请求缓冲的数据量, 其中包括文件上传,可以通过访问 RequestLengthDiskThreshold 属性或通过设置 httpRuntime 元素的 requestLengthDiskThreshold 属性 (ASP.NET 设置架构)元素或 网络配置文件。

Q3 : 您可以在web.config中指定最大上传大小:如何在 ASP.NET 中增加最大上传文件大小?