Throwing a 404 when rewriting urls

I

IanW

Hi,

I'd just like some advice on the best way to throw a 404 when
rewriting urls. The scenario is as follows:

My url is /products/redwidgets

This redirects fine to ~products.aspx?id=redwidgets

I then do a db lookup to see if redwidgets exists, but it doesn't. At
this point I want to throw a 404 error.

Should I create a 404.aspx page and server.transfer to that, or is
there some other way?

Thanks.
 
I

IanW

So Do I put this code in the products.aspx page?

HttpContext.Current.Response.StatusCode = 404;
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
return;

I have the following in web.config, but the current solution does not
redirect to the actual error page. How would I accomplish that?

<customErrors mode="Off">
<error statusCode="404" redirect="~/404.aspx"/>
</customErrors>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top