G
Guest
I have had no luck with the following scenario:
One of our requirements for a particular business scenario is to test the
existance of a URL before sending the client there. If the URL does not
exist, then we send them to another page.
To test the destination page, I use this code:
bool foundUrl = true;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
try
{
request.Method = "HEAD";
request.GetResponse();
//no probs so continue to destination
HttpContext.Current.Response.Redirect(destinationUrl, true);
}
catch (WebException webEx)
{
foundUrl = false;
}
finally
{
if (requestCheck != null)
{
requestCheck.Abort();
}
}
The problem I have now is that Response is stuck in Status 404. It will not
allow me to Redirect. I have tried the following workarounds to no avail:
1) Response.Write("<script
language=javascript>window.navigate('mynewpage.aspx');</script>")
Response.End
2)
Response.ClearHeaders();
Response.ClearContent();
Response.Redirect('mynewpage.aspx');
One of our requirements for a particular business scenario is to test the
existance of a URL before sending the client there. If the URL does not
exist, then we send them to another page.
To test the destination page, I use this code:
bool foundUrl = true;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
try
{
request.Method = "HEAD";
request.GetResponse();
//no probs so continue to destination
HttpContext.Current.Response.Redirect(destinationUrl, true);
}
catch (WebException webEx)
{
foundUrl = false;
}
finally
{
if (requestCheck != null)
{
requestCheck.Abort();
}
}
The problem I have now is that Response is stuck in Status 404. It will not
allow me to Redirect. I have tried the following workarounds to no avail:
1) Response.Write("<script
language=javascript>window.navigate('mynewpage.aspx');</script>")
Response.End
2)
Response.ClearHeaders();
Response.ClearContent();
Response.Redirect('mynewpage.aspx');