404 redirects in code with ASP.NET

I have had problems doing proper 404 redirects in ASP.NET ever since i started to care about proper 404 pages. I do not have any troubles if the page really does not exist. But say for example that i require a querystring on some page and for some reason i do not get a querystring. [...]