Response.StatusCode problem

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?
 
B

Brian Williams

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
 
G

Guest

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

Mark Rae [MVP]

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();
 
G

Guest

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();
}

:
 
L

LVP

I tried this and it works, no problem. At least in my case on my machine
and environment.
 
M

Mark Rae [MVP]

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...?
 
G

Guest

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.

 
L

LVP

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();

}
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top