设置了maxRequestLength编程 [英] Setting maxRequestLength programmatically

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

问题描述

有所谓的配置值的maxRequestLength 。在配置文件中,它看起来是这样的:

There's a configuration value called maxRequestLength. In a config file it looks like this:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="2048576" />
  </system.web>
</configuration>

如何设置的值的maxRequestLength 编程?

推荐答案

您不能!

的maxRequestLength 是由<一个处理href="http://msdn.microsoft.com/en-us/library/system.web.httpworkerrequest%28v=vs.71%29.aspx">HttpWorkerRequest之前调用实际的HttpHandler ,这意味着通用的处理程序或页面执行后,该请求点击服务器已经由相应的处理asp.net工作者。你不能有超过任何控制在的maxRequestLength 在你的页面code或一个HttpHandler!

maxRequestLength is handled by the HttpWorkerRequest prior the call to the actual HttpHandler, meaning that a generic handler or a page is executed after the request hit the server and has processed by the corresponding asp.net worker. you cannot have any control over the maxRequestLength in your page code or an HttpHandler!

如果你想读在$ C $的要求长度C,你可以做到这一点无论是通过 HTTP模块的Global.asax 的文件,这是它是如何在Global.asax内部完成:

If you want to read the request length in code you can do that either through a HttpModule or the global.asax file, this is how it is done inside the global.asax:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    IServiceProvider provider = (IServiceProvider)HttpContext.Current;
    HttpWorkerRequest workerRequest = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));

    if (workerRequest.HasEntityBody())
    {
        long contentLength = long.Parse((workerRequest.GetKnownRequestHeader(HttpWorkerRequest.HeaderContentLength)));
    }
}

您可以设置的maxRequestLength 的web.config 到最大值,并呼吁工人的<一个href="http://msdn.microsoft.com/en-us/library/system.web.httpworkerrequest.closeconnection.aspx">CloseConnection在code方法如果请求长度达到所需的值!

You could set the maxRequestLength in your web.config to its max value and call the worker's CloseConnection method in your code if the request length reaches the desired value!

这篇关于设置了maxRequestLength编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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