WebResourceAttribute 클래스

정의

어셈블리에 있는 포함 리소스를 사용할 수 있도록 하는 메타데이터 특성을 정의합니다. 이 클래스는 상속될 수 없습니다.

public ref class WebResourceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)]
public sealed class WebResourceAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)>]
type WebResourceAttribute = class
    inherit Attribute
Public NotInheritable Class WebResourceAttribute
Inherits Attribute
상속
WebResourceAttribute
특성

예제

이 섹션에는 두 코드 예제가 있습니다. 첫 번째 코드 예제에서는 적용 하는 방법에 설명 합니다 WebResourceAttribute 특성을 사용자 지정 컨트롤을 정의 하는 네임 스페이스 MyCustomControl. 두 번째 코드 예제를 사용 하는 방법에 설명 합니다 MyCustomControl 웹 페이지에는 클래스입니다.

다음 코드 예제에 적용 하는 방법을 보여 줍니다.는 WebResourceAttribute 이미지 웹 리소스와 HTML 웹 리소스를 정의 하는 사용자 지정 어셈블리에는 특성입니다. MyCustomControl 클래스 정의의 값을 설정 하는 리소스를 사용 하는 복합 컨트롤을 ImageUrl 의 속성을 Image 설정 하며 복합 컨트롤에서 포함 된 컨트롤을 HRef 속성은 HtmlAnchor HTML 리소스에 연결 하는 컨트롤입니다.

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);
        }
    }
}
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

다음 코드 예제를 사용 하는 방법에 설명 합니다 MyCustomControl 웹 페이지에는 클래스입니다.

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<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="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 xmlns="http://www.w3.org/1999/xhtml" >
<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>

이 예제에서는 포함 된 어셈블리를 사용 하 여 Image1.jpg 및 Help.htm 리소스를 컴파일하는 MyCustomControl합니다. 자세한 내용은 /resource (C# 컴파일러 옵션) 하거나 /resource (Visual Basic)합니다.

이 예제에서 사용할 수 있는 HTML 웹 리소스의 예로 다음이 표시 됩니다. 사용 하 여 합니다 WebResource 설정할 때 사용 되는 구문 합니다 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>

설명

WebResourceAttribute 클래스 어셈블리 선언에 사용 되는 경우에 유효 합니다. 웹 리소스 사용에 대 한 어셈블리에 지정된 된 포함 된 리소스를 사용 하도록 설정 하는 것이 됩니다.

리소스에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Page Resources Overview합니다.

생성자

WebResourceAttribute(String, String)

지정한 웹 리소스와 리소스 내용 형식을 사용하여 WebResourceAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

CdnPath

웹 리소스에 포함된 CDN(Content Delivery Network)의 경로를 가져오거나 설정합니다.

CdnSupportsSecureConnection

HTTPS를 사용하여 페이지에 액세스할 때 CDN(콘텐츠 배달 네트워크) 경로에 대한 보안 연결을 사용하여 스크립트 리소스에 액세스해야 하는지 여부를 ScriptManager에 나타내는 값을 가져오거나 설정합니다.

ContentType

WebResourceAttribute 클래스에서 참조하는 리소스의 MIME 형식이 들어 있는 문자열을 가져옵니다.

LoadSuccessExpression

웹 리소스가 성공적으로 로드되었을 때 사용되는 식을 가져오거나 설정합니다.

PerformSubstitution

WebResourceAttribute 클래스에서 참조하는 포함 리소스를 처리하는 동안 리소스의 전체 경로를 사용하여 다른 웹 리소스 URL이 구문 분석되고 배치되는지 여부를 확인하는 부울 값을 가져오거나 설정합니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)
WebResource

WebResourceAttribute 클래스에서 참조하는 리소스 이름이 들어 있는 문자열을 가져옵니다.

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보