Evaluar y enviar comentarios
Contraer todo/Expandir todo Contraer todo
Esta página es específica de
Microsoft Visual Studio 2005/.NET Framework 2.0

Hay además otras versiones disponibles para:
Biblioteca de clases de .NET Framework
HttpListenerContext.Response (Propiedad)

Nota: esta propiedad es nueva en la versión 2.0 de .NET Framework.

Obtiene el objeto HttpListenerResponse que se enviará al cliente en respuesta a la solicitud del cliente.

Espacio de nombres: System.Net
Ensamblado: System (en system.dll)

Visual Basic (Declaración)
Public ReadOnly Property Response As HttpListenerResponse
Visual Basic (Uso)
Dim instance As HttpListenerContext
Dim value As HttpListenerResponse

value = instance.Response
C#
public HttpListenerResponse Response { get; }
C++
public:
property HttpListenerResponse^ Response {
    HttpListenerResponse^ get ();
}
J#
/** @property */
public HttpListenerResponse get_Response ()
JScript
public function get Response () : HttpListenerResponse

Valor de propiedad

Un objeto HttpListenerResponse que permite devolver una respuesta al cliente.

Su aplicación configura la respuesta estableciendo las propiedades del objeto HttpListenerResponse devuelto por esta propiedad. Después de configurar la respuesta, se envía al cliente cerrando la respuesta o cerrando este objeto HttpListenerContext.

Notas para los llamadores Nota: Este miembro envía la información de seguimiento al habilitar el seguimiento de la red en su aplicación. Para obtener más información, vea Seguimiento de la red.

En el ejemplo de código siguiente se muestra cómo obtener la respuesta a la solicitud de un cliente y agregar el cuerpo de la respuesta.

C#
// This example requires the System and System.Net namespaces.
public static string ClientInformation(HttpListenerContext context)
{
    System.Security.Principal.IPrincipal user = context.User;
    System.Security.Principal.IIdentity id = user.Identity;
    if (id == null)
    {
        return "Client authentication is not enabled for this Web server.";
    }
    
    string display;
    if (id.IsAuthenticated)
    {
        display = String.Format("{0} was authenticated using {1}", id.Name, 
            id.AuthenticationType);
    }
    else
    {
       display = String.Format("{0} was not authenticated", id.Name);
    }
    return display;
}

public static void SimpleListenerWithAuthentication(string[] prefixes)
{
    if (!HttpListener.IsSupported)
    {
        Console.WriteLine ("Windows XP SP2 or Server 2003 is required to use the HttpListener class.");
        return;
    }

    // URI prefixes are required,
    // for example "http://contoso.com:8080/index/".
    if (prefixes == null || prefixes.Length == 0)
      throw new ArgumentException("prefixes");

    // Set up a listener.
    HttpListener listener = new HttpListener();
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    // Specify Negotiate as the authentication scheme.
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
    Console.WriteLine("Listening...");
    // GetContext blocks while waiting for a request. 
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    // Obtain a response object.
    HttpListenerResponse response = context.Response;
    // Construct a response.
    string clientInformation = ClientInformation(context);
    byte[] buffer = System.Text.Encoding.UTF8.GetBytes("<HTML><BODY> " + clientInformation + "</BODY></HTML>");
    // Get a response stream and write the response to it.
    response.ContentLength64 = buffer.Length;
    System.IO.Stream output = response.OutputStream;
    output.Write(buffer,0,buffer.Length);
    output.Close();
    listener.Stop();
}

Windows 98, Windows Server 2003, Windows XP Media Center, Windows XP SP2, Windows XP Starter Edition

.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.

.NET Framework

Compatible con: 2.0
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2012 Microsoft. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker