0

I have an image upload tool and I want to report an error before the file is uploaded if the size is too large for my server.

Is there a c# ASP .NET MVC 5 command for finding out this size?

I don't know if it makes a difference but i'm hosted with Microsoft Azure.

Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233

2 Answers2

1

You'd have to write a controller action that queried the IIS configuration and returned the value to the client.

The client would need to call this method to find out the limit before attempting the upload.

A way to find out the value is described here: How to read maxAllowedContentLength

Community
  • 1
  • 1
paul
  • 21,653
  • 1
  • 53
  • 54
1

You server application can to know this value, by reading Web.config:

var section = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection;

// Value in KBs. 4096 means 4Mb.
var maxRequestLength = section.MaxRequestLength;
Mark Shevchenko
  • 7,937
  • 1
  • 25
  • 29
  • Thanks... I have set it in my web config file (which I didn't know I had to do) and now the value appears in code.. Thanks bro! – Jimmyt1988 May 22 '15 at 11:11