StatusCode Property

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 typeCondition


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

Community Additions

© 2015 Microsoft