I know it is an old question, but it cost me so much time (wasted) that I felt like posting a working solution for those who might come in my path:
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 that you first download and install the Microsoft Web Administration package
(
PM> Install-package Microsoft.Web.Administration
)
Also, you might need to adjust permission to your web.config file. Give IUSR and IIS_IUSRS at least "Read" permission.
The code is actually from Microsoft site, though to find it took forever! Hopefully I have saved you couple of hours.
Cheers,
Roman
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…