简体   繁体   中英

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.

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. What you need to do instead is do it from the client-side, on the success handler:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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