简体   繁体   English

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

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

I have been trying to redirect to an aspx page along with a QueryString through an Ajax call but even thought the handler is called the redirect does not take place. 我一直试图通过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) {
}

}); });

Any advice perhaps as to why the transfer does not take place and how to do this 任何关于为什么不进行转移以及如何做到这一点的建议

kind regards 亲切的问候

Since you are doing an ajax request clearly the Redirect should have no effect. 由于您正在执行ajax请求,因此重定向应该没有效果。 What you need to do instead is do it from the client-side, on the success handler: 您需要做的是从客户端,在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
    }
});

Now, if this is all you are doing in the ashx handler, I don't really see the need for the ajax request. 现在,如果这是你在ashx处理程序中所做的一切,我真的不认为需要ajax请求。

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

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