Response.StatusCode problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. I need use http header StatusCode as response.
For example my page have name check.aspx and I get request like this
check.aspx?idcustomer=1395

I use this idcustomer param to check if this customer exist in my database
and if exist show page (http StatusCode == 200), but if customer with number
1395 not exist I need make 404 http error (page not exist)

I am tring to do something like
protected void Page_Load(object sender, EventArgs e)
{
Response.StatusCode = 404;
Response.End();
}

but it doesn't work. Can you somebody help me with it?
 
Not sure why you are attempting to use Response.StatusCode in this manner.
What you could do is in you SQL if the user was not found return zero then
check for values greater then zero and perform whatever action you wish from
the returned value.



Regards,

Brian K. Williams
 
Forget about sql. It is just example. The question is how I can send http 404
response from exist page?
 
Forget about sql. It is just example. The question is how I can send http
404
response from exist page?

Response.StatusCode = 404;
Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
 
Thank you, Mark.
But when I use this code and open this page in browser I see just empty page.
If http responce 404 browser should show - page not found, isn't it?

protected void Page_Load(object sender, EventArgs e)
{
Response.StatusCode = 404;
Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
}

:
 
I tried this and it works, no problem. At least in my case on my machine
and environment.
 
Thank you, Mark.
But when I use this code and open this page in browser I see just empty
page.
If http response 404 browser should show - page not found, isn't it?

Hmm - it works for me...

What version of IIS are you using...?
 
I use VS2005 for run this page and also put into IIS6.0 and see the same
result.
Just empty page, but without 404 error.

 
this is what I have.

if you put the following code in your page load by itself then you should
get what Mark said the 404

protected void Page_Load(object sender, EventArgs e)

{

Response.StatusCode = 404;

Response.SuppressContent = true;

HttpContext.Current.ApplicationInstance.CompleteRequest();

}
 
Back
Top