c# - asp.net mvc 中的 HttpPostedFileBase 状态

标签 c# asp.net asp.net-mvc file-upload

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 操作是完成),计时结束。我怎么知道用户什么时候开始上传?

最佳答案

首先,看一下这个问题的基础知识:File Upload ASP.NET MVC 3.0

Q1:一旦文件完全可用,就会调用该操作。

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

The amount of data that is buffered in server memory for a request, which includes file uploads, can be specified by accessing the RequestLengthDiskThreshold property or by setting the requestLengthDiskThreshold attribute of the httpRuntime Element (ASP.NET Settings Schema) element within the Machine.config or Web.config file.

Q3:您可以在 web.config 中指定最大上传大小:How to increase the max upload file size in ASP.NET?

关于c# - asp.net mvc 中的 HttpPostedFileBase 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14577562/

相关文章:

asp.net - 如何在转发器模板中动态设置控件 ID?

c# - 格式化字符串电话号码 MVC Razor 而不解析为十进制

asp.net-mvc - Webforms 与 Asp.Net MVC VS2010 负载测试

c# - Javascript 函数参数未显示在 Asp.Net MVC RouteValueDictionary 中?

c# - 奇怪的 Visual Studio 行为

c# - 将列表或数组从 Arden MLM 传递到 C#

asp.net - 找不到我的函数?

asp.net - 在根站点下托管的应用程序中配置子目录身份验证模式

c# - 按版本对字符串列表进行排序

C# 应用程序设置