【问题标题】:asp filter ajax and usual request [closed]asp过滤器ajax和通常的请求[关闭]
【发布时间】:2013-11-16 09:15:57
【问题描述】:

我在Net4.0 有asp 网页。在这个版本中,我不能使用异步方法。我有 ajax 容器:UpdatePanel。我在此面板中有按钮。当我按下按钮时,页面不会重新加载并且在调试模式下我会看到页面加载方法。我需要过滤 ajax 请求和通常。我该怎么办?

像这样:

protected void Page_Load(object sender, EventArgs e)
{
  if(request.isAsync)
  {
    //this is ajax
  }else
  {
     //this is usual request.
  }

}

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您可以使用here的扩展方法

    public static bool IsAjaxRequest(this HttpRequest request)
    {
        if (request == null)
        {
            throw new ArgumentNullException("request");
        }
    
        return (request["X-Requested-With"] == "XMLHttpRequest") || ((request.Headers != null) && (request.Headers["X-Requested-With"] == "XMLHttpRequest"));
    }
    

    然后做:

    if(request.IsAjaxRequest())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多