ClientScriptManager.GetWebResourceUrl(Type, String) 메서드

정의

어셈블리의 리소스에 대한 URL 참조를 가져옵니다.

public:
 System::String ^ GetWebResourceUrl(Type ^ type, System::String ^ resourceName);
public string GetWebResourceUrl(Type type, string resourceName);
member this.GetWebResourceUrl : Type * string -> string
Public Function GetWebResourceUrl (type As Type, resourceName As String) As String

매개 변수

type
Type

리소스의 형식입니다.

resourceName
String

어셈블리에 있는 리소스의 정규화된 이름입니다.

반품

리소스에 대한 URL 참조입니다.

예외

웹 리소스 유형은 .입니다 null.

-또는-

웹 리소스 이름은 .입니다 null.

-또는-

웹 리소스 이름의 길이는 0입니다.

예제

다음 코드 예제에서는 메서드의 사용을 보여 줍니다 GetWebResourceUrl . 이 예제의 형식 매개 변수는 리소스를 포함하는 어셈블리의 클래스 형식으로 설정됩니다. resourceName 매개 변수는 기본 네임스페이스를 포함하는 리소스에 대한 정규화된 경로로 지정됩니다.

<%@ Page Language="C#"%>
<%@ Import Namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  public void Page_Load(Object sender, EventArgs e)
  {
    // Define the resource name and type.
    String rsname = "Samples.AspNet.CS.Controls.script_include.js";
    Type rstype = typeof(ClientScriptResourceLabel);
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Write out the web resource url.
    ResourcePath.InnerHtml = cs.GetWebResourceUrl(rstype, rsname);

    // Register the client resource with the page.
    cs.RegisterClientScriptResource(rstype, rsname);

  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     The web resource path is 
     <span  id="ResourcePath"
            runat="server"/>.
     <br />
     <br />
     <input type="text" 
            id="Message" />     
     <input type="button" 
            onclick="DoClick()" 
            value="ClientClick" />
     </form>
  </body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="Samples.AspNet.VB.Controls" %>

<!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)

    ' Define the resource name and type.
    Dim rsname As String = "Samples.AspNet.VB.Controls.script_include.js"
    Dim rstype As Type = GetType(ClientScriptResourceLabel)
    
    ' Get a ClientScriptManager reference from the Page class.
    Dim cs As ClientScriptManager = Page.ClientScript
    
    ' Write out the web resource url.
    ResourcePath.InnerHtml = cs.GetWebResourceUrl(rstype, rsname)
    
    ' Register the client resource with the page.
    cs.RegisterClientScriptResource(rstype, rsname)
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     The web resource path is 
     <span  id="ResourcePath"
            runat="server"/>.
     <br />
     <br />
     <input type="text" 
            id="Message" />     
     <input type="button" 
            onclick="DoClick()" 
            value="ClientClick" />
     </form>
  </body>
</html>

다음 코드 예제에서는 메타데이터 특성을 프로그래밍 방식으로 적용 WebResourceAttribute 하여 제공될 리소스에 대한 어셈블리를 표시하는 방법을 보여 줍니다. 사용 중인 언어에 따라 기본 네임스페이스를 설정 Samples.AspNet.CS.Controls 하거나 Samples.AspNet.VB.Controls사용하는 클래스 라이브러리에서 다음 클래스를 컴파일합니다.

using System;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;

[assembly: WebResource("Samples.AspNet.CS.Controls.script_include.js", "application/x-javascript")]
namespace Samples.AspNet.CS.Controls
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class ClientScriptResourceLabel
    {
        // Class code goes here.
    }
}
Imports System.Web
Imports System.Web.UI
Imports System.Security.Permissions

<Assembly: WebResource("Samples.AspNet.VB.Controls.script_include.js", "application/x-javascript")> 
Namespace Samples.AspNet.VB.Controls

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class ClientScriptResourceLabel

        ' Class code goes here.

    End Class

End Namespace

이 예제에는 이름이 Script_include.jsJavaScript 파일이 필요합니다. .js 파일은 개체를 포함하는 어셈블리에 포함된 리소스입니다 ClientScriptResourceLabel . Visual Studio 사용하는 경우 클래스 라이브러리 프로젝트의 속성 창 스크립트 파일을 선택할 때 Build ActionEmbedded Resource로 설정합니다. 명령줄에서 라이브러리를 컴파일하는 경우 /resource 스위치를 사용하여 리소스를 포함합니다.

function DoClick() {Form1.Message.value='Text from resource script.'}

설명

이 메서드는 GetWebResourceUrl 어셈블리에 포함된 리소스에 대한 URL 참조를 반환합니다. 반환된 참조가 URL로 인코딩되지 않았습니다. 리소스는 스크립트 파일, 이미지 또는 정적 파일일 수 있습니다. 리소스에 액세스할 개체에 따라 형식을 지정합니다.

페이지에 등록된 웹 리소스는 해당 유형과 이름으로 고유하게 식별됩니다. 지정된 형식 및 이름 쌍을 가진 하나의 리소스만 페이지에 등록할 수 있습니다. 이미 등록된 리소스를 등록하려고 시도해도 등록된 리소스가 중복되지 않습니다.

GetWebResourceUrl 메서드는 어셈블리에 포함된 리소스에 액세스하는 메서드와 RegisterClientScriptResource 함께 사용됩니다. 애플리케이션에서 리소스를 사용하는 방법에 대한 자세한 내용은 ASP.NET 웹 페이지 리소스 개요 참조하세요.

적용 대상

추가 정보