在.NET中是否有一类用于设置HttpResponse.StatusDescription的常量?

发布于 2024-10-11 11:22:27 字数 245 浏览 4 评论 0原文

我正在使用 c# 并修改从服务器返回的 HttpResponse 。我在 HttpStatusCode 中找到了一个具有所有相关状态代码的枚举,但我无法找到一个包含字符串常量的随附类来设置 HttpResponse.StatusDescription 属性。

难道只是因为它不存在吗?或者描述实际上是自由文本,只要您设置相对描述性的内容就可以了?

预先感谢您的帮助, 缺口

I am using c# and modifying the HttpResponse returned from the server. I have found an enumeration which has all the relevant status codes in HttpStatusCode but i am having trouble finding an accompanying class which holds string constants to set the HttpResponse.StatusDescription property.

Is it simply the case that it doesn't exist? Or that the description is effectively free-text, as long as you set something relatively descriptive you'll be ok?

Thanks in advance for the help,
Nick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆那么伤 2024-10-18 11:22:27

您只需使用 HttpStatusCode.*MEMBER*.ToString() 即可获取枚举的字符串值。

示例:HttpStatusCode.OK.ToString()

You could just use HttpStatusCode.*MEMBER*.ToString() to get the string value of the Enumeration.

Example: HttpStatusCode.OK.ToString()

别在捏我脸啦 2024-10-18 11:22:27

您可以在很大程度上自由地将任何文本插入到 StatusDescription 中,只要字符串不超过 HTTP 允许的最大长度(iirc 这是 512 个字符)。

例如,如果您要设置 500 错误(内部服务器错误),您可以添加进一步的描述,以允许调用者获取与发生的错误相关的附加信息。

StatusDescription 属性默认为“OK”。

可以在此处找到更多信息:

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.statusdescription.aspx

还值得一提的是,在大多数实现中,不使用状态描述的值。大多数服务调用程序使用实际状态代码来确定成功、失败或其他条件(即重定向、未找到等)

You are largely free to insert whatever text you want into the StatusDescription, as long as the string does not exceed the maximum lenght allowed by HTTP (iirc this is 512 characters).

As an example if you were to set a 500 error (internal server error) you could put a further description in to allow invokers to get additional information relating to the error that occurred.

The StatusDescription property defaults to "OK"

A little more information can be found here:

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.statusdescription.aspx

It is also worth mentioning that in most implementations the value of status description is not used. Most service invokers use the actual status code to determine success, failure or other conditions (i.e. redirected, not found etc)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文