加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

在asp.net mvc上传文件代码后,通过服务器获取“连接重置”错误

发布时间:2020-12-16 00:28:36 所属栏目:asp.Net 来源:网络整理
导读:我已经阅读了几个问题,解释如何处理asp.net mvc中的文件上传。我试图提交文件以及描述它的表单域。这可能是问题。我会去写代码: 查看代码: % using (Html.BeginForm("CreateFile","Video",FormMethod.Post,new { enctype = "multipart/form-data" })) {%
我已经阅读了几个问题,解释如何处理asp.net mvc中的文件上传。我试图提交文件以及描述它的表单域。这可能是问题。我会去写代码:

查看代码:

<% using (Html.BeginForm("CreateFile","Video",FormMethod.Post,new { enctype = "multipart/form-data" }))

   {%>

    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="file">Filename:</label>
            <input type="file" name="file" id="file" />            
        </p>
        <p>
            <label for="Password">Password:</label>
            <%= Html.TextBox("Password")%>
            <%= Html.ValidationMessage("Password","*")%>
        </p>
        <p>
            <label for="Description">Description:</label>
            <%= Html.TextBox("Description")%>
            <%= Html.ValidationMessage("Description","*")%>
        </p>
        <p>
            <label for="DateUploaded">DateUploaded:</label>
            <%= Html.TextBox("DateUploaded")%>
            <%= Html.ValidationMessage("DateUploaded","*")%>
        </p>
        <p>
            <label for="DateRecorded">DateRecorded:</label>
            <%= Html.TextBox("DateRecorded")%>
            <%= Html.ValidationMessage("DateRecorded","*")%>
        </p>
        <p>
            <input type="submit" value="Submit" />
        </p>
    </fieldset>

<% } %>

控制器代码:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateFile(VideoDTO video,HttpPostedFileBase f)   //[Bind(Exclude="VideoId")]
{            
    foreach (string file in Request.Files)
    {
        HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
        if (hpf.ContentLength == 0)
            continue;
        string savedFileName = Server.MapPath("Videos") + Path.GetFileName(hpf.FileName);

        hpf.SaveAs(savedFileName);
        video.FileName = hpf.FileName;
    }

    repository.CreateVideo(video);
    return RedirectToAction("Index");            
}

我看过几个例子,但没有遇到一个试图提交文件和其他表单数据的例子。另外还有一些其他的例子似乎没有把HttpVerb属性放在action方法上,并且有一个空参数字符串。我想要接受的文件将是各种类型的视频文件,但它们可以在100-300 mb的任何地方。我试图使用(本地)的文件相对较少(50左右)。

我知道这是被问到,但我觉得我的问题在某种程度上是不一样的。当我提交页面我看到:

The connection was reset

The connection to the server was reset
while the page was loading.

解决方法

你调整了web.config中的maxRequestLength吗?
问题是请求大小大于您提供的值。更改web.config的system.web config部分的httpRuntime部分中的maxRequestLength,以接受更大的值。
<System.Web>
    <httpRuntime maxRequestLength="value in kilobytes" />
</System.Web>

你也必须注意超时值。

祝你好运!。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读