从asp.net页面codebehind 404错误响应 [英] respond with 404 error from asp.net page codebehind

查看:138
本文介绍了从asp.net页面codebehind 404错误响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的服务从codebehind一个文件一个场景

该文件,取决于请求。在某些情况下,不会有文件服务,我想回到404浏览器。

which file, depends on request. in some cases there will be no file to serve and I want to return 404 to the browser.

我怎么能做到这一点从codebehind?这是正确的行动过程,以显示用户有没有文件可用?

how can I do that from codebehind? is this the correct course of action to show user there's no file available?

推荐答案

您可以使用Response.Status$c$c属性返回404:

you can use the Response.StatusCode property to return a 404:

Page.Response.StatusCode = 404

至于它是否就是我会说这取决于页面将如何被访问的做正确的事的问题。如果你想以编程方式访问它,然后是的,我会用404去然而,如果这将是一个面向用户的系统,那么我会用某种自定义的页面去。像codeS和人类一样的程序更容易理解的事情: - )

As for the question of whether it's the "correct thing to do" I'd say it depends how the Page is going to be accessed. If you're going to access it programmatically then yes I'd go with the 404. If however it is going to be a user facing system, then I'd go with a custom page of some sort. Programs like codes and humans like more understandable things :-)

这篇关于从asp.net页面codebehind 404错误响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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