在asp.net mvc 页面里上传大文件到服务器端,需要如下步骤:

1. 在Control类里添加get 和 post 方法

         // get method
public ActionResult Upload()
{
return View();
} // This action handles the form POST and the upload
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > )
{
// extract only the fielname
var fileName = Path.GetFileName(file.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Upload");
}

2. 创建view页面,并且添加如下代码:

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}

3. 在Web.config里做如下添加和修改:

在<system.web>里添加

<httpRuntime targetFramework="4.5" maxRequestLength="1048576" executionTimeout="3600"/>

并且在<system.webServer>里添加

    <security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>

大功告成!

转载请注明出处:http://www.cnblogs.com/beiyeqingteng/

在asp.net mvc中上传大文件的更多相关文章

  1. ASP.NET MVC 上传大文件时404

    前一段时间会员的上传组件改用FLASH的swfupload来上传,既能很友好的显示上传进度,又能完全满足大文件的上传. 后来服务器升级到windows 2008,改为IIS7后,上传文件一旦超过30M ...

  2. Ajax在ASP.NET MVC中上传

    HomeController.cs using System; using System.Collections.Generic; using System.Linq; using System.We ...

  3. [Asp.net]Uploadify上传大文件,Http error 404 解决方案

    引言 之前使用Uploadify做了一个上传图片并预览的功能,今天在项目中,要使用该插件上传大文件.之前弄过上传图片的demo,就使用该demo进行测试.可以查看我的这篇文章:[Asp.net]Upl ...

  4. [Asp.net]Uploadify上传大文件,Http error 404 解决方案 - wolfy

    引言 之前使用Uploadify做了一个上传图片并预览的功能,今天在项目中,要使用该插件上传大文件.之前弄过上传图片的demo,就使用该demo进行测试.可以查看我的这篇文章: [Asp.net]Up ...

  5. c# asp.net uploadify 上传大文件 出现的 HTTP 404 问题

    用uploadify在IIS6下上传大文件没有问题,但是迁移到IIS7下面,上传大文件时,出现HTTP 404错误. 查了半天,原来是IIS7下的默认设置限制了上传大小.这个时候Web.Config中 ...

  6. C# Asp.NET实现上传大文件(断点续传)

    以ASP.NET Core WebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API ,包括文件的上传和下载. 准备文件上传的API #region 文件上传  ...

  7. asp.net fileupload上传大文件时提示404.13错误

    IIS 7 默认文件上传大小时30M 要突破这个限制,需要做如下操作: 1. 修改IIS的applicationhost.config     打开 %windir%\system32\inetsrv ...

  8. 如何在ASP.NET Core中上传超大文件

    HTML部分 <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="index.aspx. ...

  9. asp.net mvc 上传下载文件的几种方式

    view: <!DOCTYPE html> <html> <head> <meta name="viewport" content=&qu ...

随机推荐

  1. php empty函数

    empty — 检查一个变量是否为空. 当一个变量并不存在,或者它的值等同于FALSE,那么它就会被认为不存在.如果变量不存在的话,empty()并不会产生警告. 返回值: 当var存在,并且是一个非 ...

  2. 负margin小记

    static元素  margin-top/left负值,元素向指定方向移动,               margin-bottom/right负值,元素不动,后续元素前移 float元素   左浮, ...

  3. 使用proguard混淆java web项目代码

    1.首先下载proGuard.zip到本地: proguard4.5beta4.tar.zip解压开,2.新建文本文档,修改文件名为XXX.pro,然后复制下面内容到.pro -injars 'Y:\ ...

  4. vim黏贴代码格式混乱的解决方法

    from:http://blog.csdn.net/commshare/article/details/6215088 感谢牛人的文章.解决了我在vim使用中,很头疼的问题. 在vim新建文件的时候, ...

  5. ASP.NET中最保险最环保的返回404的方法

    代码如下: Response.StatusCode = 404; Response.SuppressContent = true; Context.ApplicationInstance.Comple ...

  6. mongodb 与 c++ 的配合使用

    最近在尝试使用 mongodb 作为服务端持久化方案,服务端程序是使用 c++ 写的,折腾了不少时间,记录一下吧. 1.下载 boost 1.56.0 http://www.boost.org/use ...

  7. PHP跳转页面的几种实现方法详解

    •PHP页面跳转一.header()函数header()函数是PHP中进行页面跳转的一种十分简单的方法.header()函数的主要功能是将HTTP协议标头(header)输出到浏览器.header() ...

  8. PHP 如何显示大数字,防止显示为 科学计数法 形式

    PHP 数字超过一定长度时,会自动转换为 科学计数法 的形式,如 1.2345678912346E+16: 如何 避免转换,让它原样展示呢? 不过,可以用PHP函数 number_format() 来 ...

  9. json不转化值是null的字段

    今天写东西,发现JSONObject.fromObject(),方法,会把value是null的字段,转为0或"",就自己写了一个方法,如果value是null就不转换 packa ...

  10. maven项目如何使用jetty启动?

    1.在pom.xml文件中插入下面的片段 <build> <plugins> <plugin> <groupId>org.eclipse.jetty&l ...