简体   繁体   English

如何在ASP.NET中以C#作为代码,以编程方式设置(使用GET SET属性)“ httpRuntime maxRequestLength”

[英]How to programmatically set (using GET SET property) “httpRuntime maxRequestLength” in ASP.NET with C# as code behind

How to programmatically set (using GET SET property) "httpRuntime maxRequestLength" in ASP.NET with C# as code behind 如何以C#作为代码在ASP.NET中以编程方式设置(使用GET SET属性)“ httpRuntime maxRequestLength”

is there any way to set values in web.config through C# ? 有什么办法可以通过C#在web.config设置值?

You can set the web.config's maxRequestLength property in code like this: 您可以通过如下代码设置web.config的maxRequestLength属性:

Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( "~" );
var section = (System.Web.Configuration.SystemWebSectionGroup)webConfig.GetSectionGroup("system.web");
section.HttpRuntime.MaxRequestLength = 10 * 1024; // 10 MB
webConfig.Save();

We do this exact thing in our Rock RMS content management system. 我们在Rock RMS内容管理系统中做到这一点

Yes, you can set it in the web.config 是的,您可以在web.config设置

Just set it in the web.config under the <system.web> section. 只需在<system.web>部分下的web.config进行设置即可。 In the below example I am setting the maximum length to 2GB 在下面的示例中,我将maximum length设置为2GB

<httpRuntime maxRequestLength="2097152" executionTimeout="600" />

Please note that the maxRequestLength is set in KB's and it can be set up to 2GB ( 2079152 KB's ). 请注意, maxRequestLengthKB's为单位设置,最大可设置为2GB( 2079152 KB's )。 But default file size limit is (4MB) . 但是默认文件大小限制为(4MB)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET C#从Code Behind设置OnSelectedIndexChanged - ASP.NET C# Set OnSelectedIndexChanged from Code Behind 使用ASP.Net和C#在代码中将Data URI设置为asp:Image - Set Data URI to asp:Image in code behind using ASP.Net and C# 如何在javascript中设置asp.net隐藏字段并访问c#代码后面的值 - how to set asp.net hidden field in javascript and access the value in c# code behind 如何在C#ASP.NET背后的代码中将背景图像设置为:: before选择器 - How to set background-image to ::before selector in code behind C# ASP.NET 设置文字 <p> 从c#asp.net中的代码嵌入在asp:Panel中 - Set text in <p> embedded in asp:Panel from code behind c# asp.net 时间:2019-05-10标签:c#aspnet如何根据用户权限使用背后的代码设置元素的启用和可见属性 - c# asp net how to set enabled and visible properties of elements using code behind according to user permissions 如何从app_code中的类设置母版页中的属性? 与asp.net C# - How to set property in master page from class in app_code? with asp.net c# ASP.NET - 未调用隐藏代码 (C#) - AutoEventWireup 设置为 True - ASP.NET - Code behind (C#) not being called - AutoEventWireup is set to True 从C#Asp.net后面的代码设置输入文本字段的值 - Set the value of input text field from code behind C# Asp.net C#如何在使用asp.net mvc时设置autopostback属性? - C# How to set the autopostback property when using asp.net mvc?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM