Hi,
How can I create a 404 error from the code, which will look on the
client side _exactly the same_ as he was trying to access a non
existing page ?
I want to use to filter users.
e.g., in global.asax:
pseudo code:
=========================
Application_BeginRequest(..)
{
if Request.Url.LocalPath.Contains("admin")
{
// next 2 lines no good since client doesnt see the "404" page
Response.Status = 404;
Response.End
}
}
=========================
The above code is not good enough for me, since the client is not
redirected to see a 404 in the browser,
or redirected to the 404 page which is web.config
I can use "Response.Redirect("404.aspx") for the custom 404 page,
but I want a "real" 404.
Thanks for any help.
George Ter-Saakov - 26 Oct 2007 13:58 GMT
There is no "Real" 404 page.......
If user's browser has option "show friendly page" turned on in IE then user
will see it with one condition. Your output is less than 256 bytes (or 512,
do not remember).
Other than that it's everything you will output to the browser.
so just add Response.Write("404 page") 100 times and you will see it in a
browser.
George.
> Hi,
>
[quoted text clipped - 26 lines]
>
> Thanks for any help.
Mark Rae [MVP] - 26 Oct 2007 14:39 GMT
> pseudo code:
> =========================
[quoted text clipped - 8 lines]
> }
> =========================
real code:
//=========================
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if Request.Url.LocalPath.Contains("admin")
{
HttpContext.Current.Response.StatusCode = 404;
HttpContext.Current.Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
return;
}
}
//=========================

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Si - 28 Oct 2007 11:23 GMT
Hi
Thanks for your answers.
The code you've suggested didnt result in causing the browser to show
a "404" page, just a blank page.
I've found a different way to do which I'm not is the correct\best
way, but it works:
if Request.Url.LocalPath.Contains("admin")
{
throw new HttpException(404,"");
}
Thanks for your help.
Mark Rae [MVP] - 29 Oct 2007 00:08 GMT
> The code you've suggested didnt result in causing the browser to show
> a "404" page, just a blank page.
Hmm - that's curious - it works fine for me...
What version of IIS are you using, AAMOI...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net