开发者

In .NET is there a class of constants for setting HttpResponse.StatusDescription?

开发者 https://www.devze.com 2023-02-02 19:58 出处:网络
I am using c# and modifying the Ht开发者_JAVA技巧tpResponse returned from the server. I have found an enumeration which has all the relevant status codes in HttpStatusCode but i am having trouble find

I am using c# and modifying the Ht开发者_JAVA技巧tpResponse 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


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

Example: HttpStatusCode.OK.ToString()


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号