Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'connection reset by server' error in asp.net mvc upload file code after submit

I've read several questions explaining how to handle file uploads in asp.net mvc. I am trying to submit both the file as well as form fields describing it. That might be the issue. I'll go write to the code:

View code:

<% 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>

<% } %>

Controller code:

[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");            
}

I've seen several examples, but haven't come across one that is trying to submit both a file and other form data. Some other things of note is other examples seem to not put a HttpVerb attribute on the action method at all and have an empty parameter string. The files I'm looking to accept will be video files of various types but they can be anywhere from 100-300 mb. The files I've attempted to use (locally) have been rather small comparatively (50 or so mb).

I know it's been asked but I feel like my issue here is different somehow. When I submit the page I see:

The connection was reset

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

like image 452
jason Avatar asked Mar 06 '10 16:03

jason


1 Answers

Did you tuned the maxRequestLength in the web.config? The problem is that the request size is greater than the value you have provided. Change the maxRequestLength in the httpRuntime section of the system.web config section of your web.config to accept greater values.

<System.Web>
    <httpRuntime maxRequestLength="value in kilobytes" />
</System.Web>

You'll have to pay attention to the timeout value too.

Good luck!.

like image 131
uvita Avatar answered Nov 06 '22 21:11

uvita