Hi, i got a problem when i try to upload an image bigger than 4,8 MB, the page goes in time out.. i guess…
error :
[HttpException (0x80004005): Maximum request length exceeded.]
I tryied to add this code in my web.config
<location path="Creation/CreationUpload">
<system.web>
<httpRuntime executionTimeout="1000"/>
</system.web>
</location>
but it does not work
this is the code in my controller :
// POST: /Creation/CreationUpload
// Afin de déjouer les attaques par sur-validation, activez les propriétés spécifiques que vous voulez lier. Pour
// plus de détails, voir http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[Authorize]
[ValidateAntiForgeryToken]
public ActionResult CreationUpload([Bind(Include = "CreationId,CreationTitle,CreationPhotoBis")] Creation creation, IEnumerable<HttpPostedFileBase> files)
{
if (ModelState.IsValid)
{
// update each field manually
foreach (var file in files)
{
if (file != null)
{
if (file.ContentLength > 0)
{
var myuploadextension = Path.GetExtension(file.FileName);
if (myuploadextension.ToUpper() == ".JPEG" || myuploadextension.ToUpper() == ".JPG" || myuploadextension.ToUpper() == ".BMP" || myuploadextension.ToUpper() == ".PNG" || myuploadextension.ToUpper() == ".GIF")
{
var sizeMb = (file.ContentLength / 1024f) / 1024f; //file.contentlength is in bytes
var todaydate = DateTime.Now.ToShortDateString();
var todaydatefriendly = todaydate.ImageFriendly();
var myuploadiwthoutextension = Path.GetFileNameWithoutExtension(file.FileName);
var myuploadiwthoutextensionfriendly = myuploadiwthoutextension.ImageFriendly();
var UserId = User.Identity.GetUserId();
var fileName = todaydatefriendly + "-" + UserId + "-" + myuploadiwthoutextensionfriendly + myuploadextension;
var path = Path.Combine(Server.MapPath("~/Content/UserCreations"), fileName);
file.SaveAs(path);
//Language
var actualculturetocheck = "en";
var actualculture = this.Session["ActualCulture"];
if (actualculture != null)
{
actualculturetocheck = actualculture.ToString();
}
//Ipaddress
var ipAddress = Request.ServerVariables["REMOTE_ADDR"] + " " + Request.UserHostAddress;
creation.UserId = User.Identity.GetUserId();
creation.CreationLanguage = actualculturetocheck;
creation.CreationVisible = true;
creation.CreationDelete = false;
creation.CreationDate = DateTime.Now;
creation.CreationIpAdress = ipAddress;
creation.CreationPhotoBis = fileName; //after add
db.Creations.Add(creation);
db.SaveChanges();
}
}
}
}
//UserId
return RedirectToAction("CreationList", "Creation", new { UserId = User.Identity.GetUserId() });
}
return View(creation);
}
what should i do to increase the ScriptTimeout in my contorller action?
FULL ERROR WHEN I TRY TO UPLOAD :
[HttpException (0x80004005): Maximum request length exceeded.]
System.Web.HttpRequest.GetEntireRawContent() +9553280
System.Web.HttpRequest.GetMultipartContent() +63
System.Web.HttpRequest.FillInFormCollection() +165
System.Web.HttpRequest.EnsureForm() +75
System.Web.HttpRequest.get_Form() +12
System.Web.HttpRequestWrapper.get_Form() +9
System.Web.Mvc.HttpRequestExtensions.GetHttpMethodOverride(HttpRequestBase request) +121
System.Web.Mvc.AcceptVerbsAttribute.IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) +37
System.Web.Mvc.HttpPostAttribute.IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) +39
System.Web.Mvc.ActionMethodSelectorBase.IsValidMethodSelector(ReadOnlyCollection`1 attributes, ControllerContext controllerContext, MethodInfo method) +54
System.Web.Mvc.ActionMethodSelectorBase.RunSelectionFilters(ControllerContext controllerContext, List`1 methodInfos) +124
System.Web.Mvc.ActionMethodSelectorBase.FindActionMethods(ControllerContext controllerContext, String actionName) +142
System.Web.Mvc.ActionMethodSelectorBase.FindActionMethod(ControllerContext controllerContext, String actionName) +104
System.Web.Mvc.Async.ReflectedAsyncControllerDescriptor.FindAction(ControllerContext controllerContext, String actionName) +54
System.Web.Mvc.ControllerActionInvoker.FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, String actionName) +16
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +114
System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +25
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +468
System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +18
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +20
System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +374
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +16
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__3(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +52
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +384
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Thanks
grafic.web
[HttpException (0x80004005): Maximum request length exceeded.]
This error is related to the size of the uploaded file. You need to increase the Request length
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>
For IIS versions older than 7 use this
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
If you are going to be working with files that are larger than the default of 4MB, you’ll need to update the maxRequestLength within your
web.config to handle files of that size. This can be handled within the <system.web> section of your web.config or the <system.webServer> section if you want to handle it at the IIS level (both are probably a good idea).
It’s important to know that maxAllowedContentLength is measured in bytes and maximumRequestLength is measured in kilobytes when settings these values so you’ll need to adjust them accordingly if you plan on handling much larger files :
<configuration>
<system.web>
<!-- This will handle requests up to 30MB -->
<httpRuntime maxRequestLength="30720" timeout="3600" />
</system.web>
</configuration>
<!-- IIS Specific Targeting (noted by the system.webServer section) -->
<system.webServer>
<security>
<requestFiltering>
<!-- This will handle requests up to 30MB -->
<requestLimits maxAllowedContentLength="31457280" />
</requestFiltering>
</security>
</system.webServer>
If you don’t see these sections within your existing web.config file, you’ll simply need to copy them in.