如何阅读maxAllowedContentLength [英] How to read maxAllowedContentLength

查看:1017
本文介绍了如何阅读maxAllowedContentLength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的web应用程序,我有文件上传flash组件。我想处理在客户端的最大文件大小限制没有实际发送的文件服务器。所以我需要读取配置文件,该值以某种方式将其发送给客户端。我发现有些文章说,直接读取配置文件不解决方案,因为它可以在一大堆的地方进行更改。所以,应该有一定的API调用可能,但我无法找到任何...

 < system.webServer>
    <安全>
        <&的requestFiltering GT;
            < requestLimits maxAllowedContentLength =1048576/>
        < /&的requestFiltering GT;
    < /安全>
< /system.webServer>


解决方案

试试这个方法。

您可以更改基于配置文件的Web配置code的下方段

我的web.config一些看起来像

 <&的System.Web GT;
  <的httpRuntime executionTimeout =30的maxRequestLength =100/>

在这里,您可以看到的maxRequestLength 被定义为100,可以从网页背后code更改

添加使用System.Web.Configuration;

现在写这篇code键更改的maxRequestLength

的价值

 配置配置= WebConfigurationManager.OpenWebConfiguration(〜);
HttpRuntimeSection httpruntinesec =
    (HttpRuntimeSection)configuration.GetSection(System.Web程序/的httpRuntime);

您可以使用httpruntinesce实例设置的值。

For my web app i have flash component for uploading files. I would like to handle max file size limit on client side without actual sending that file to server. So i need to read that value from config file somehow to send it to client. Some articles i had found said that reading directly config file is not solution, because it can be changed in whole lot of places. So there should be some API call probably, but i cannot find any...

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="1048576" />
        </requestFiltering>
    </security>
</system.webServer>

解决方案

Try this way

You can change the below segment of code based on the web configuration in the config file

My web.config some look like

<system.web>
  <httpRuntime executionTimeout="30"  maxRequestLength="100"/>

Here you can see maxRequestLength is defined as 100 which can be changed from code behind page

Add using System.Web.Configuration;

Now write this code to change the value of maxRequestLength

Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");
HttpRuntimeSection httpruntinesec =
    (HttpRuntimeSection)configuration.GetSection("system.web/httpRuntime");

You can use httpruntinesce instance set the value.

这篇关于如何阅读maxAllowedContentLength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆