WebResourceAttributeとは? わかりやすく解説

WebResourceAttribute クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

アセンブリ内の埋め込みリソース有効にするメタデータ属性定義します。このクラス継承できません。

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

<AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple:=True)> _
Public NotInheritable Class
 WebResourceAttribute
    Inherits Attribute
Dim instance As WebResourceAttribute
[AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=true)]
 
public sealed class WebResourceAttribute :
 Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly, AllowMultiple=true)]
 
public ref class WebResourceAttribute sealed
 : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=true)
 */ 
public final class WebResourceAttribute extends
 Attribute
AttributeUsageAttribute(AttributeTargets.Assembly, AllowMultiple=true)
 
public final class WebResourceAttribute extends
 Attribute
解説解説
使用例使用例

このセクションには、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") %> />

Included help file.

</div>

</body>

</html>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Attribute
    System.Web.UI.WebResourceAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebResourceAttribute コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定されWeb リソースリソース コンテンツ タイプで WebResourceAttribute クラス新しインスタンス初期化します。

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

例外例外
例外種類条件

ArgumentException

webResourcenull 参照 (Visual Basic では Nothing) か空の文字列 ("") です。

または

contentTypenull 参照 (Visual Basic では Nothing) か空の文字列 ("") です。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebResourceAttribute クラス
WebResourceAttribute メンバ
System.Web.UI 名前空間

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebResourceAttribute クラス
System.Web.UI 名前空間
Attribute

その他の技術情報

ASP.NET Web ページリソース概要
アプリケーションリソース
/resource (出力へのリソース ファイル埋め込み) (C# コンパイラ オプション)
/resource (Visual Basic)

WebResourceAttribute メンバ

アセンブリ内の埋め込みリソース有効にするメタデータ属性定義します。このクラス継承できません。

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebResourceAttribute クラス
System.Web.UI 名前空間
Attribute

その他の技術情報

ASP.NET Web ページリソース概要
アプリケーションリソース
/resource (出力へのリソース ファイル埋め込み) (C# コンパイラ オプション)
/resource (Visual Basic)



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「WebResourceAttribute」の関連用語

WebResourceAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebResourceAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS