I know this is an old question, but it cost me so much time (wasted) that I wanted to publish a working solution for those who might come my way:
Using Microsoft.Web.Administration; uint uiMaxAllowedContentLength = 0; using (ServerManager serverManager = new ServerManager()) { Configuration config = serverManager.GetWebConfiguration("Default Web Site/{{your special site}}"); ConfigurationSection requestFilteringSection = config.GetSection("system.webServer/security/requestFiltering"); ConfigurationElement requestLimitsElement = requestFilteringSection.GetChildElement("requestLimits"); object maxAllowedContentLength = requestLimitsElement.GetAttributeValue("maxAllowedContentLength"); if (null != maxAllowedContentLength) { uint.TryParse(maxAllowedContentLength.ToString(), out uiMaxAllowedContentLength); } }
Make sure you first download and install the Microsoft web administration package (
PM> Microsoft.Web.Administration Installation Package
)
In addition, you may need to configure permission for your web.config file. Give IUSR and IIS_IUSRS at least Read permission.
The code is actually from the Microsoft site, although finding it forever! I hope I saved you a couple of hours.
Greetings
Roman
Roman source share