Asp.net mvc Asp.Net MVC:URL过长的请求和错误处理

Asp.net mvc Asp.Net MVC:URL过长的请求和错误处理,asp.net-mvc,iis-7,error-handling,Asp.net Mvc,Iis 7,Error Handling,通过查看我的elmah日志,我发现我一直收到“太长的url”请求。错误是: System.Web.HttpException (0x80004005): The length of the URL for this request exceeds the configured maxUrlLength value. at System.Web.HttpRequest.ValidateInputIfRequiredByConfig() at System.Web.HttpApplica

通过查看我的elmah日志,我发现我一直收到“太长的url”请求。错误是:

System.Web.HttpException (0x80004005): The length of the URL for this request exceeds the configured maxUrlLength value.
   at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
   at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
以下是我收到的请求类型:

/index.php/blog/post/the_datetimepicker的_ten_欺骗/+[PLM=0]+GET+http:/www.visualhint.com/index.php/blog/post/the_datetimepicker的_ten_欺骗/+[02377823037]+>+[N]+post+http:/www.visualhint.com/index.php/blog/post/the_datetimepicker的_ten欺骗/[0,02007]

(不要对php感到惊讶……在成为asp.NETMVC网站之前,我的网站是php的,现在我需要将这种旧url重定向到我的新url格式,当url停在/index.php/blog/post/the_tenu欺骗_the_datetimepicker时,这种格式很好用)

  • 什么可以产生这些请求?听起来有恶意吗

  • 我有自定义错误设置,所以我认为这样的请求会被重定向到我的自定义错误页面,但事实并非如此。相反,人们会得到典型的黄色屏幕(firebug提到这是一个错误的请求)。如果您查看上面的堆栈跟踪,它非常短,并且异常似乎很早就被捕获(甚至没有调用应用程序_BeginRequest)。是否可以显示我的自定义错误页面,或者在发生此类异常时,我是否至少可以重定向到我的主页

  • 我尝试在我的web.config中添加一行错误400:

    <customErrors mode="RemoteOnly">
        <error statusCode="400" redirect="/" />
    </customErrors>
    
    
    
    这会重定向到主页右侧,但会在aspxerrorpath查询字符串值中添加完整的url


    谢谢你的帮助。

    谷歌搜索帮助我发现有些人收到了这种请求。有人回答说:

    我很确定这是一种自动提交垃圾邮件的方式。一定有 是配置中的一个错误,因为它不应留下这样的 在推荐人领域有着丰富的线索

    首先它告诉一些脚本获取一个URL,然后它指示发布到 URL(很容易阻止直接发布的垃圾邮件,而不必获取 首先)

    这些数字可能与要发布的垃圾邮件有关(想想看) 将其作为垃圾邮件数据库中的索引)

    因此,由于这些请求很有可能不是来自正常链接的人类,因此我最终得到了以下解决方案。这样可以避免污染我的elmah日志,并为调用者提供一个带有404代码的空白页面:

    public void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
    {
        HttpException hExc = e.Exception.GetBaseException() as HttpException;
        if (hExc != null)
        {
            if (hExc.ErrorCode == unchecked((int)0x80004005))
            {
                e.Dismiss();
                return;
            }
        }
    
        // Here I do some stuff if the error has to be logged.
    }
    
    void Application_Error(object sender, EventArgs e)
    {
        Exception exc = Server.GetLastError();
        HttpException hExc = exc as HttpException;
        if (hExc != null)
        {
            if (hExc.ErrorCode == unchecked((int)0x80004005))
            {
                Uri uri = HttpContext.Current.Request.Url;
    
                Response.Clear();
                Response.StatusCode = 404;
                Response.End();
    
                Server.ClearError();
            }
        }
    }
    
    与其返回404代码,我更希望不发送响应(调用者将有一个超时),但asp.net是否可以?不知道…

    这里的建议可能会有帮助: