다음을 통해 공유


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

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

반환

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

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

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

설명

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

페이지를 사용 하 여 등록 된 웹 리소스는 해당 유형과 이름으로 고유 하 게 식별 됩니다. 지정 된 형식 및 이름 쌍을 사용 하 여 하나의 리소스 페이지를 사용 하 여 등록할 수 있습니다. 이미 등록 되어 있는 리소스를 등록 하는 동안 등록 된 리소스의 중복을 만들지 않습니다.

GetWebResourceUrl 메서드를 함께에서 사용 된 RegisterClientScriptResource 어셈블리에 포함 된 리소스에 액세스 하기 위한 메서드. 애플리케이션에서 리소스 사용에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Page Resources Overview합니다.

적용 대상

추가 정보