Using RewritePath - but I want to send the user to a 404

K

Klaus Jensen

For a customer I have created a website, where we use dynamic url-rewrites
by using rewritepath in global.asa.

Ie the url /products/gizmo.aspx does not really exist, but I look gizmo up
in the db and find the relevant product, and then do a rewritepath to
productpresentation.aspx?id=whatever

But in some cases, I get a request for /products/someoddproduct.aspx which
does not exist. I then want to send the user a 404-error from code. How do I
do that?

Thanks in advance

- Klaus
 
G

Greg Young [MVP]

By simply not rewriting the URL this should happen.

Which URL rewriting setup are you using?

Cheers,

Greg
 
K

Klaus Jensen

Greg Young said:
By simply not rewriting the URL this should happen.

I'm sitting here laughing at myself... I dont know why I did not think of
that. Thanks. :)
Which URL rewriting setup are you using?

In Application_BeginRequest I evaluate the URL. If it's
/Products/Gizmo.aspx, I look in the db for the product gizmo, retrieve the
pageId for it and rewrite the url to Productpresentation.aspx?id=xxx

And now if gizmo does not exist, I keep my dirty paws off the big red
"RewriteUrl"-button.:D
 
J

John Timney \( MVP \)

This did make me smirk a bit...........lol

Incidentally, the code you would have needed had you been catching this and
trying to provide a response would be something like this.

Response.StatusCode = 404;
Response.StatusDescription = "Not Found";
Response.Write("<h2>Page not found</h2>");
Response.End();
--
Regards

John Timney
Microsoft MVP
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top