2011-08-04 69 views
3

通过检查我的elmah日志,我看到我不断收到“太长的url”请求。错误是:Asp.Net MVC:具有太长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_ten_deceptions_of_the_datetimepicker/+[PLM=0]+GET+http:/www .visualhint.com/index.php的/博客/后/ the_ten_deceptions_of_the_datetimepicker/+ [0,23778,23037] + - > + [N] + POST HTTP +:/www.visualhint.com/index.php/blog/post/ the_ten_deceptions_of_the_datetimepicker/+ [0,0,2007]

(不要惊讶于php的事情......在成为一个asp.net mvc网站之前,我的网站当URL停在/index.php/blog/post/the_ten_deceptions_of_the_datetimepicker是PHP,现在我需要这种旧网址重定向到我新的URL格式,效果很好)

  1. 什么能产生这些要求?它听起来有恶意吗?

  2. 我有自定义错误设置,所以我虽然这样的请求将被重定向到我的自定义错误页面,但事实并非如此。相反,人们会得到典型的黄色屏幕(萤火虫提到这是一个400坏请求)。如果你看看上面的堆栈跟踪,它非常短,异常似乎很早被捕获(Application_BeginRequest甚至没有被调用)。是否有可能显示我的自定义错误页面,或者我能否至少在发生这种异常时重定向到我的主页?

我尝试添加错误400线在我的web.config:

<customErrors mode="RemoteOnly"> 
    <error statusCode="400" redirect="/" /> 
</customErrors> 

这重定向到网页的权利,但它增加了完整的URL在aspxerrorpath查询字符串值。

感谢您的帮助。

+0

这里的建议可能有帮助:http://stackoverflow.com/questions/1185739/asp-net-mvc-url-routing-maximum-path-url-length –

回答

1

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

我很确定这是一种自动提交垃圾邮件的方式。必须有 在配置中出现错误,因为它不应该在引荐来源字段中留下这样一个多汁的踪迹!

首先它告诉某个脚本获得一个URL,然后它指示发送到 一个URL(它很容易阻止垃圾邮件直接发布POST,而不是首先得到 )。

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

因此,由于很有可能这些请求不是来自正常链接之后的人类,我最终得到了以下解决方案。这避免了污染我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?不知道...