Share via


HttpServerUtility クラス

Web 要求を処理するヘルパ メソッドを提供します。

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public NotInheritable Class HttpServerUtility
'使用
Dim instance As HttpServerUtility
public sealed class HttpServerUtility
public ref class HttpServerUtility sealed
public final class HttpServerUtility
public final class HttpServerUtility
適用できません。

解説

HttpServerUtility クラスのメソッドとプロパティは、ASP.NET の組み込み Server オブジェクトをとおして公開されます。

使用例

HttpServerUtility クラスの HtmlEncode メソッドおよび UrlEncode メソッドを使用する方法を次のコード例に示します。HtmlEncode メソッドを使用すると、ユーザーが入力した文字列が、実行可能スクリプト コードや解釈された HTML 要素ではなくブラウザに静的テキストとして表示されるようにできます。UrlEncode メソッドを使用すると、URL は、HTTP ストリームで正しく送信されるようにエンコードされます。

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        If (Not String.IsNullOrEmpty(TextBox1.Text)) Then
            
            ' Access the HttpServerUtility methods through
            ' the intrinsic Server object.
            Label1.Text = "Welcome, " & _
                Server.HtmlEncode(TextBox1.Text) & _
                ".<br/> The url is " & _
                Server.UrlEncode(Request.Url.ToString())
        End If
        
        
        
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>HttpServerUtility Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Enter your name:<br />

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
        <br />
        <asp:Label ID="Label1" runat="server"/>
        </div>
    </form>
</body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(TextBox1.Text))
        {
            // Access the HttpServerUtility methods through
            // the intrinsic Server object.
            Label1.Text = "Welcome, " +
                Server.HtmlEncode(TextBox1.Text) +
                ".<br/> The url is " + 
                Server.UrlEncode(Request.Url.ToString());
        }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>HttpServerUtility Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Enter your name:<br />

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
        <br />
        <asp:Label ID="Label1" runat="server"/>
        </div>
    </form>
</body>
</html>

.NET Framework のセキュリティ

継承階層

System.Object
  System.Web.HttpServerUtility

スレッド セーフ

この型の public static (Visual Basicでは共有) メンバはすべて,スレッド セーフです。インスタンス メンバの場合は,スレッド セーフであるとは限りません。

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

HttpServerUtility メンバ
System.Web 名前空間
HttpContext