ClientScriptManager.GetWebResourceUrl メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As ClientScriptManager Dim type As Type Dim resourceName As String Dim returnValue As String returnValue = instance.GetWebResourceUrl(type, resourceName)
戻り値
リソースへの URL 参照。


GetWebResourceUrl メソッドは、アセンブリに埋め込まれているサーバー側リソースへの URL 参照を返します。返される参照は URL エンコードされません。スクリプト ファイル、イメージ、または静的ファイルがリソースになります。
GetWebResourceUrl メソッドは、アセンブリ内に埋め込まれているリソースにアクセスする RegisterClientScriptResource メソッドと併用されます。アプリケーションでリソースを使用する方法の詳細については、「ASP.NET Web ページのリソースの概要」を参照してください。

GetWebResourceUrl メソッドの使用方法を示すコード例を次に示します。
<%@ Page Language="VB" %> <%@ Import Namespace="Samples.AspNet.VB.Controls" %> <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 = "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> <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="C#"%> <%@ Import Namespace="Samples.AspNet.CS.Controls" %> <script runat="server"> public void Page_Load(Object sender, EventArgs e) { // Define the resource name and type. String rsname = "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> <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 メタデータ属性を適用し、提供されるリソースについてアセンブリにマークを付ける方法を次のコード例に示します。
Imports Microsoft.VisualBasic Imports System Imports System.Web Imports System.Web.UI Imports System.Security.Permissions <Assembly: WebResource("script_include.js", "application/x-javascript")> Namespace Samples.AspNet.VB.Controls <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _ Public Class ClientScriptResourceLabel ' Put code here that would ' go into the private assembly. End Class End Namespace
using System; using System.Web; using System.Web.UI; using System.Security.Permissions; [assembly: WebResource("script_include.js", "application/x-javascript")] namespace Samples.AspNet.CS.Controls { [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)] public class ClientScriptResourceLabel { // Put code here that would // go into the private assembly. } }
この例では、次のような内容の Script_include.js という名前の JavaScript ファイルが必要です。
Samples.AspNet.CS.Controls.ClientScriptResourceLabel クラスが含まれるアセンブリ内に Script_include.js ファイルをリソースとしてコンパイルします。

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


Weblioに収録されているすべての辞書からClientScriptManager.GetWebResourceUrl メソッドを検索する場合は、下記のリンクをクリックしてください。

- ClientScriptManager.GetWebResourceUrl メソッドのページへのリンク