Response.StatusCode问题 [英] Response.StatusCode problem

查看:128
本文介绍了Response.StatusCode问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我需要使用http标头StatusCode作为响应。

例如我的页面有名称check.aspx我得到这样的请求

check.aspx?idcustomer = 1395


我使用这个idcustomer param来检查我的数据库中是否存在此客户

以及是否存在显示页面(http StatusCode == 200),但如果客户编号为

1395不存在我需要make 404 http错误(页面不存在)


我想要做类似的事情

protected void Page_Load(object sender,EventArgs e)

{

Response.StatusCode = 404;

Response.End();

}


但它不起作用。你可以帮助我吗?

解决方案

不确定为什么你试图以这种方式使用Response.StatusCode。

你可以做的是在你的SQL中如果没有找到用户返回零然后

检查大于零的值并执行你想要的任何动作

返回价值。


问候,


Brian K. Williams


" SushiSean" < su ******* @ discuss.microsoft.com写信息

新闻:B8 ********************* ************* @ microsof t.com ...


你好。我需要使用http标头StatusCode作为响应。

例如我的页面有名称check.aspx我得到这样的请求

check.aspx?idcustomer = 1395


我使用这个idcustomer param检查这个客户是否存在于我的数据库中

并且如果存在显示页面(http StatusCode == 200),但是如果客户有

数字

1395不存在我需要make 404 http错误(页面不存在)


我想做一些像

protected void Page_Load(object sender,EventArgs e)

{

Response.StatusCode = 404;

Response.End ();

}


但它不起作用。你能帮助我吗?



忘了sql。这只是一个例子。问题是如何从现有页面发送http 404

响应?


Brian Williams写道:


不确定为什么你试图以这种方式使用Response.StatusCode。

你可以做的是你的SQL如果用户未找到返回零然后

检查大于零的值并执行您希望的任何操作

返回值。


" SushiSean" < su ******* @ discuss.microsoft.com写信息

news:99 ********************* ************* @ microsof t.com ...


>不知道为什么你试图以这种方式使用Response.StatusCode。
如果没有找到用户,你可以做的就是在你的SQL中返回零
然后检查值是否大于零,并执行你想要的任何动作
返回的值。


忘掉sql。这只是一个例子。问题是如何从现有页面发送http

404

回复?



Response.StatusCode = 404;

Response.SuppressContent = true;

HttpContext.Current.ApplicationInstance。 CompleteRe quest();

-

Mark Rae

ASP.NET MVP
http://www.markrae.net


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

"SushiSean" <Su*******@discussions.microsoft.comwrote in message
news:B8**********************************@microsof t.com...

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?



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

"Brian Williams" wrote:

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.


"SushiSean" <Su*******@discussions.microsoft.comwrote in message
news:99**********************************@microsof t.com...

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

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.CompleteRe quest();
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


这篇关于Response.StatusCode问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆