Search code examples
asp.net.netvisual-studio-2010code-behind

How to write raw html to browser from code behing in asp.net


I want to write a raw html page to the browser. I thought that something liek this would do it but this write to the current page:

Dim html as New StringBuilder
html.append("<html><body>A new html page</body></html>"
Response.Clear()
Response.Output.Write(html.ToString)

I know this can be done I just can't remember how


Solution

  • You have to get the context object and then you can use something like this:

    context.Response.Clear();
    
    //Response.Charset = "UTF-8";
    context.Response.ContentType = "text/html"
    
    context.Response.AddHeader("Content-Length", length);
    
    context.Response.OutputStream.Write((byte[])buffer, 0, filesize);