0

I have a .Net Core MVC 3.1 Web Application where i have to upload a file, and i want that file to be with a max size of 100MB. I'm trying to display an error using the app.UseExceptionHandler, but it doesn't work. I even used a custom middleware to try to see where the request goes and it doesn't go there.

Startup.cs

//app.UseExceptionHandler("/Errores"); <-- Tryed this and all the ways with useStatusCode...
        //if (env.IsDevelopment())
        //{
        //    app.UseDeveloperExceptionPage();
        //}
        //else
        //{
        //    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        //    app.UseHsts();
        //}

        app.Use(async (context, next) =>
        {
            //try
            //{
                await next(); <-- It doesn't even reach here
            //}
            //catch { }
            if (context.Response.StatusCode == 413)
            {
                context.Request.Path = "/Error/404";
                await next();
            }
        });

        app.UseHttpsRedirection();
        app.UseFileServer();
        app.UseCookiePolicy();

        app.UseRouting();
        app.UseSession();

        app.UseAuthentication();

        // Add MVC to the request pipeline.
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Login}/{action=Index}/{id?}");

            endpoints.MapControllerRoute(
                name: "Errores",
                pattern: "Errores/{action}",
                defaults: new { controller = "Errores" });
        });

413.1 error

The controller is like this

    public ActionResult PostAyuda([FromForm] AyudaRequest dataRequest)
    {

Any help?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 2
    Looks like the error message is generated by IIS. Have you examined the IIS configuration to see what limits are in place? – mason Jun 16 '21 at 13:27
  • Yes, i have the limit on 50MB and i don't want more size. The thing is that i want to change that screen to be one custom done by me. – Diego Jimenez Jun 17 '21 at 11:33

0 Answers0