Page.Server プロパティ
アセンブリ: System.Web (system.web.dll 内)
構文
解説
使用例
Server オブジェクトを使用して、サーバーからエラー情報にアクセスする方法を次のコード例に示します。この例では、要求された URL を Request オブジェクトから取得し、(GetLastError メソッドを使用して) 直前のエラーを Server オブジェクトから取得して、この両方をクライアントが表示できる文字列に変換しています。message 変数がクライアントに書き込まれると、ClearError メソッドを使用してエラーが削除されます。
Protected Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Dim sb As New StringBuilder() sb.Append("URL that caused the error: <br/>") sb.Append(Server.HtmlEncode(Request.Url.ToString())) sb.Append("<br/><br/>") sb.Append("Error message: <br/>") sb.Append(Server.GetLastError().ToString()) Response.Write(sb.ToString()) Server.ClearError() End Sub
protected void Page_Error(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append("URL that caused the error: <br/>"); sb.Append(Server.HtmlEncode(Request.Url.ToString())); sb.Append("<br/><br/>"); sb.Append("Error message: <br/>"); sb.Append(Server.GetLastError().ToString()); Response.Write(sb.ToString()); Server.ClearError(); }
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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- Page.Server プロパティのページへのリンク