Writes a string to an HTTP response output stream.
Assembly: System.Web (in System.Web.dll)
Public Sub Write ( _ s As [%$TOPIC/1463ysyw_en-us_VS_110_1_0_0_0_0%] _ )
public void Write( [%$TOPIC/1463ysyw_en-us_VS_110_1_0_1_0_0%] s )
public: void Write( [%$TOPIC/1463ysyw_en-us_VS_110_1_0_2_0_0%]^ s )
member Write : s:[%$TOPIC/1463ysyw_en-us_VS_110_1_0_3_0_0%] -> unit
The string to write to the HTTP output stream.
Dynamically generated HTML pages can introduce security risks if input received from Web clients is not validated either when it is received from a client or when it is transmitted back to a client. Malicious script that is embedded in input submitted to a Web site and later written back out to a client can appear to be originating from a trusted source. This security risk is referred to as a cross-site scripting attack. You should always validate data that is received from a client when it will be transmitted from your site to client browsers.
Moreover, whenever you write out as HTML any data that was received as input, you should encode it using a technique such as HtmlEncode or UrlEncode to prevent malicious script from executing. This technique is useful for data that was not validated when it was received.
When you encode or filter data, you must specify a character set for your Web pages so that your filter can identify and remove any byte sequences that do not belong to that set (such as nonalphanumeric sequences) and could potentially have malicious script embedded in them.
For more information about cross-site scripting attacks, see article Q252985, "How to Prevent Cross-Site Scripting Security Issues" on the Microsoft Knowledge Base Web site.
The following example echoes the client's name back to the client's browser. The HtmlEncode method strips any malicious script and invalid characters that may have been submitted in the UserName input field.
Response.Write("Hello " & Server.HtmlEncode(Request.QueryString("UserName")) & "<br>")
Response.Write("Hello " + Server.HtmlEncode(Request.QueryString["UserName"]) + "<br>");
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.