WebResourceAttribute クラス
アセンブリ: System.Web (system.web.dll 内)

<AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple:=True)> _ Public NotInheritable Class WebResourceAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=true)] public sealed class WebResourceAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly, AllowMultiple=true)] public ref class WebResourceAttribute sealed : public Attribute

WebResourceAttribute クラスは、アセンブリ宣言で使用される場合のみ有効です。アセンブリ内の指定された埋め込みリソースを Web リソースとして使用できるようにする場合に、このクラスを使用します。

このセクションには、2 つのコード例が含まれています。最初のコード例では、カスタム コントロール MyCustomControl を定義する名前空間に WebResourceAttribute 属性を適用する方法を示しています。2 つ目のコード例では、Web ページで MyCustomControl クラスを使用する方法を示しています。
次のコード例では、カスタム アセンブリに WebResourceAttribute 属性を適用して、イメージ Web リソースと HTML Web リソースを定義する方法を示しています。MyCustomControl クラスは、リソースを使用して、このコントロールに含まれる Image コントロールの ImageUrl プロパティ値を設定し、HTML リソースにリンクする HtmlAnchor コントロールの HRef プロパティを設定する複合コントロールを定義しています。
Imports Microsoft.VisualBasic Imports System Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.HtmlControls Imports System.Web.UI.WebControls <Assembly: WebResource("image1.gif", "image/jpeg")> <Assembly: WebResource("help.htm", "text/html", PerformSubstitution:=True)> Namespace Samples.AspNet.VB.Controls Public Class MyCustomControl Inherits Control <System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Sub CreateChildControls() ' Create a new Image control. Dim _img As New Image() _img.ImageUrl = Me.Page.ClientScript.GetWebResourceUrl(GetType(MyCustomControl), "image1.jpg") Me.Controls.Add(_img) ' Create a new Label control. Dim _lab As New Label() _lab.Text = "A composite control using the WebResourceAttribute class." Me.Controls.Add(_lab) ' Create a new HtmlAnchor control linking to help.htm. Dim a As HtmlAnchor = New HtmlAnchor() a.HRef = Me.Page.ClientScript.GetWebResourceUrl(GetType(MyCustomControl), "help.htm") a.InnerText = "help link" Me.Controls.Add(New LiteralControl("</br>")) Me.Controls.Add(a) End Sub End Class End Namespace
using System; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; [assembly: WebResource("image1.jpg", "image/jpeg")] [assembly: WebResource("help.htm", "text/html", PerformSubstitution=true)] namespace Samples.AspNet.CS.Controls { public class MyCustomControl : Control { [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] protected override void CreateChildControls() { // Create a new Image control. Image _img = new Image(); _img.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(typeof(MyCustomControl), "image1.jpg"); this.Controls.Add(_img); // Create a new Label control. Label _lab = new Label(); _lab.Text = "A composite control using the WebResourceAttribute class."; this.Controls.Add(_lab); // Create a new HtmlAnchor control linking to help.htm. HtmlAnchor a = new HtmlAnchor(); a.HRef = this.Page.ClientScript.GetWebResourceUrl(typeof(MyCustomControl), "help.htm"); a.InnerText = "help link"; this.Controls.Add(new LiteralControl("</br>")); this.Controls.Add(a); } } }
次のコード例では、Web ページで MyCustomControl クラスを使用する方法を示しています。
<%@ Page Language="VB" %> <%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB.Controls" %> <%@ Import Namespace="System.Reflection" %> <!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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' Get the assembly metatdata. Dim clsType As Type = GetType(MyCustomControl) Dim a As Assembly = clsType.Assembly For Each attr As Attribute In Attribute.GetCustomAttributes(a) 'Check for WebResource attributes. If attr.GetType() Is GetType(WebResourceAttribute) Then Dim wra As WebResourceAttribute = CType(attr, WebResourceAttribute) Response.Write("Resource in the assembly: " & wra.WebResource.ToString() & _ " with ContentType = " & wra.ContentType.ToString() & _ " and PerformsSubstitution = " & wra.PerformSubstitution.ToString() & "</br>") End If Next attr End Sub </script> <html > <head runat="server"> <title>WebResourceAttribute Example</title> </head> <body> <form id="form1" runat="server"> <div> <AspNetSamples:MyCustomControl ID="MyCustomControl1" runat="server"> </AspNetSamples:MyCustomControl> </div> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS.Controls" %> <%@ Import Namespace="System.Reflection" %> <!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 Page_Load(object sender, EventArgs e) { // Get the assembly metatdata. Type clsType = typeof(MyCustomControl); Assembly a = clsType.Assembly; // Iterate through the attributes for the assembly. foreach (Attribute attr in Attribute.GetCustomAttributes(a)) { //Check for WebResource attributes. if (attr.GetType() == typeof(WebResourceAttribute)) { WebResourceAttribute wra = (WebResourceAttribute)attr; Response.Write("Resource in the assembly: " + wra.WebResource.ToString() + " with ContentType = " + wra.ContentType.ToString() + " and PerformsSubstitution = " + wra.PerformSubstitution.ToString() + "</br>"); } } } </script> <html > <head runat="server"> <title>WebResourceAttribute Example</title> </head> <body> <form id="form1" runat="server"> <div> <AspNetSamples:MyCustomControl ID="MyCustomControl1" runat="server"> </AspNetSamples:MyCustomControl> </div> </form> </body> </html>
この例では、MyCustomControl が含まれるアセンブリで Image1.jpg リソースと Help.htm リソースをコンパイルする必要があります。詳細については、「/resource (出力へのリソース ファイルの埋め込み) (C# コンパイラ オプション)」または「/resource (Visual Basic)」を参照してください。
この例で使用できる HTML Web リソースの例を次に示します。WebResource 構文が使用されていることに注意してください。これは、Web リソースに対して PerformSubstitution プロパティを true に設定した際に使用されます。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html >
<head>
<title>Included Help Page</title>
</head>
<body>
<div>
<img alt="help image" src=<% = WebResource("image1.jpg") %> />
</div>
</body>
</html>


System.Attribute
System.Web.UI.WebResourceAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebResourceAttribute コンストラクタ
アセンブリ: System.Web (system.web.dll 内)

Public Sub New ( _ webResource As String, _ contentType As String _ )
Dim webResource As String Dim contentType As String Dim instance As New WebResourceAttribute(webResource, contentType)
public WebResourceAttribute ( string webResource, string contentType )
public: WebResourceAttribute ( String^ webResource, String^ contentType )
public WebResourceAttribute ( String webResource, String contentType )
public function WebResourceAttribute ( webResource : String, contentType : String )

例外の種類 | 条件 |
---|---|
ArgumentException | webResource が null 参照 (Visual Basic では Nothing) か空の文字列 ("") です。 または contentType が null 参照 (Visual Basic では Nothing) か空の文字列 ("") です。 |

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebResourceAttribute プロパティ

名前 | 説明 | |
---|---|---|
![]() | ContentType | WebResourceAttribute クラスによって参照されるリソースの MIME タイプを格納する文字列を取得します。 |
![]() | PerformSubstitution | WebResourceAttribute クラスによって参照される埋め込みリソースの処理中に、他の Web リソース URL を解析し、リソースの完全パスに置き換えるかどうかを示すブール値を取得または設定します。 |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。) |
![]() | WebResource | WebResourceAttribute クラスによって参照されるリソースの名前を格納する文字列を取得します。 |

WebResourceAttribute メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

WebResourceAttribute メンバ
アセンブリ内の埋め込みリソースを有効にするメタデータ属性を定義します。このクラスは継承できません。
WebResourceAttribute データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | WebResourceAttribute | 指定された Web リソースとリソース コンテンツ タイプで WebResourceAttribute クラスの新しいインスタンスを初期化します。 |

名前 | 説明 | |
---|---|---|
![]() | ContentType | WebResourceAttribute クラスによって参照されるリソースの MIME タイプを格納する文字列を取得します。 |
![]() | PerformSubstitution | WebResourceAttribute クラスによって参照される埋め込みリソースの処理中に、他の Web リソース URL を解析し、リソースの完全パスに置き換えるかどうかを示すブール値を取得または設定します。 |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。) |
![]() | WebResource | WebResourceAttribute クラスによって参照されるリソースの名前を格納する文字列を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- WebResourceAttributeのページへのリンク