【问题标题】:trying to redirect from an ashx page to an aspx page试图从 ashx 页面重定向到 aspx 页面
【发布时间】:2013-07-25 19:16:14
【问题描述】:

我一直在尝试通过 Ajax 调用与 QueryString 一起重定向到 aspx 页面,但即使调用了处理程序,也不会发生重定向。

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "text/plain";
    string searchValue = context.Request["txtBoxValue"].ToString();
    context.Response.Redirect("SearchResults.aspx?search=" + searchValue);

}

 $.ajax({
url: 'Handlers/SearchContent.ashx',
data: { 'txtBoxValue': txtBoxValue },
success: function (data) {
}

});

关于为什么不进行转移以及如何进行转移的任何建议

亲切的问候

【问题讨论】:

    标签: c# asp.net ajax handler response.redirect


    【解决方案1】:

    由于您正在执行 ajax 请求,因此重定向应该无效。您需要做的是从客户端,在 success 处理程序上:

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string searchValue = context.Request["txtBoxValue"].ToString();
        //Return the redirect URL instead
        context.Response.Write("SearchResults.aspx?search=" + searchValue);     
    }
    
    
    
    $.ajax({
        url: 'Handlers/SearchContent.ashx',
         data: { 'txtBoxValue': txtBoxValue },
          success: function (data) {
             window.location= data;//redirect here. "data" has the full URL
        }
    });
    

    现在,如果这就是您在 ashx 处理程序中所做的一切,我真的不认为需要 ajax 请求。

    【讨论】:

    • 好叫 Icarus,我没有看到 AJAX 部分;删除了我的答案。
    猜你喜欢
    • 2010-11-08
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多