WickyNilliams
WickyNilliams

Reputation: 5308

In .NET is there a class of constants for setting 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

Upvotes: 1

Views: 3394

Answers (2)

MrEyes
MrEyes

Reputation: 13750

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)

Upvotes: 2

Dan McClain
Dan McClain

Reputation: 11920

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

Example: HttpStatusCode.OK.ToString()

Upvotes: 4

Related Questions