0 out of 8 rated this helpful - Rate this topic

HttpResponse.StatusCode Property

Gets or sets the HTTP status code of the output returned to the client.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public int StatusCode { get; set; }
/** @property */
public int get_StatusCode ()

/** @property */
public void set_StatusCode (int value)

public function get StatusCode () : int

public function set StatusCode (value : int)

Property Value

An Integer representing the status of the HTTP output returned to the client. The default value is 200 (OK).
Exception type Condition

HttpException

StatusCode is set after the HTTP headers have been sent.

The following code example is an ASP.NET page that uses the StreamWriter class to write the values of three HttpResponse class properties to a text file: the StatusCode property, the StatusDescription property, and the Charset property. The code first creates a constant, named INFO_DIR, that contains the path and part of the file name for the text file. A counter is then created that is used to generate unique file names for each response. Next, the code references a StreamWriter object that will write the information about the request to the file.

The code then calls the WriteLine method to write the time the response was generated, and then writes the property values to the file. The code then closes the StreamWriter object.

// Set the Charset property to the
// Central European character set.        
Response.Charset = "iso-8859-2";

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
The Example is bogus - real example requested
The current Example doesn't do what it says it does by any stretch of the imagination. What would be good to see is an example of how to properly set the StatusCode and return it. What I was particularly interested in is if by setting the StatusCode I also have to manually reset the StatusDescription as well. And, in my application, I am desiring to set it in the context of a Web Service, and I wonder if all I need to do is clear the headers, set the StatusCode and do a Response.End()??? Off to the races to test... it sucks!