ASP.NETでサイト内で共有する固定変数を使用する
どのページからも参照できる変数を使用する。
global.aspx に Public Shared ReadOnly 変数名 で変数を定義し、値をセットする。ここでは web.config から値を取得している。
global.aspx
<%@ Application Language="VB" %>
<script runat="server">
Public Shared ReadOnly ImageURLOriginal As String = ConfigurationManager.AppSettings("ImageURLOriginal")
Public Shared ReadOnly ImageURLW1280 As String = ConfigurationManager.AppSettings("ImageURLW1280")
Public Shared ReadOnly ImageURLW600 As String = ConfigurationManager.AppSettings("ImageURLW600")
Public Shared ReadOnly ImageURLW300 As String = ConfigurationManager.AppSettings("ImageURLW300")
Public Shared ReadOnly ImageURLW150 As String = ConfigurationManager.AppSettings("ImageURLW150")
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
'
MJBTMDb.V3.TMDbTV.SetTMDbConstance(ConfigurationManager.AppSettings("tmdbAPIKey"), _
ConfigurationManager.AppSettings("TMDbTVSearchURL"), _
ConfigurationManager.AppSettings("TMDbTVAPIGetURL"), _
ConfigurationManager.AppSettings("YoutubeEmbedURL"))
End Sub
<script runat="server">
Public Shared ReadOnly ImageURLOriginal As String = ConfigurationManager.AppSettings("ImageURLOriginal")
Public Shared ReadOnly ImageURLW1280 As String = ConfigurationManager.AppSettings("ImageURLW1280")
Public Shared ReadOnly ImageURLW600 As String = ConfigurationManager.AppSettings("ImageURLW600")
Public Shared ReadOnly ImageURLW300 As String = ConfigurationManager.AppSettings("ImageURLW300")
Public Shared ReadOnly ImageURLW150 As String = ConfigurationManager.AppSettings("ImageURLW150")
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
'
MJBTMDb.V3.TMDbTV.SetTMDbConstance(ConfigurationManager.AppSettings("tmdbAPIKey"), _
ConfigurationManager.AppSettings("TMDbTVSearchURL"), _
ConfigurationManager.AppSettings("TMDbTVAPIGetURL"), _
ConfigurationManager.AppSettings("YoutubeEmbedURL"))
End Sub
Global.ASP.global_asax.変数名 で変数を使用する。
Sample.vb
ImageBackdropW600.ImageUrl = Global.ASP.global_asax.ImageURLW1280 + objTMDbTVBase.backdrop_path
コメント
コメントを投稿