首页 文章

IIS请求限制<requestLimits maxAllowedContentLength =“x”>是否可以应用于特定的ASP.NET路由?

提问于
浏览
1

我正在查看IIS 7 Request Limits <requestLimits>设置,特别是 maxAllowedContentLength ,并想知道这是否可以在ASP.NET Routing级别应用?我正在一个允许文件上传的ASP.NET MVC 3项目中工作,但我想只允许对这些特定路由的更大请求 .

这个问题类似于未答复的Can I increase maxRequestLength of ASP.NET request for MVC Controller Action with additional parameters?

Where do I catch and handle maxAllowedContentLength exceeded in IIS7?的回答似乎意味着我可以做这样的事情,但我一直在寻找确认或其他想法 .

protected override void OnError(EventArgs e)
{
    Exception err = Server.GetLastError();
    if (err is HttpException)
    {
        if ((err as HttpException).WebEventCode == 3004)
        {
            // check to see if upload request and let through
            Server.Transfer( Context.Request.Url.LocalPath );
            return;
        }
    }
    base.OnError(e);
}

1 回答

  • 1

    您可以将 <requestLimits> 元素放在 <location> 标记中,以用于与该路由对应的(虚假)虚拟目录 .

    我不知道有什么更好的解决方案 .

相关问题