繁体   English   中英

尝试从ashx页面重定向到aspx页面

[英]trying to redirect from an ashx page to an aspx page

我一直试图通过Ajax调用重定向到一个aspx页面以及QueryString但是甚至认为处理程序被称为重定向不会发生。

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) {
}

});

任何关于为什么不进行转移以及如何做到这一点的建议

亲切的问候

由于您正在执行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请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM