==[[ASP.NETバンドルでの相対パスを使用]]==
[[ASP.NET.Core]] | [[ASP.NET]] |
====App_Start/BundleConfig.cs====
using System.Web.Optimization;
namespace SalesMsReportSalesMs[[R]]eport
{
public class BundleConfig
{
// バンドルの詳細については、https://go.microsoft.com/fwlink/?LinkId=301862 を参照してください
public static void RegisterBundles[[R]]egisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
var transForm = new ApplicationContextPathTransform(appCtx);
foreach (var bundle in bundles.GetRegisteredBundlesGet[[R]]egisteredBundles())
{
bundle.Transforms.Add(transForm);
this.applicationContextPath = applicationContextPath;
}
public void Process(BundleContext context, BundleResponse Bundle[[R]]esponse response)
{
if (!string.IsNullOrEmpty(this.applicationContextPath))
// 指定されている場合、アプリケーションコンテキストパスの挿入
file.IncludedVirtualPath
= file.IncludedVirtualPath.Replace[[R]]eplace(@"~/", $@"~/{this.applicationContextPath}/");
}
}
*Web.Test.config
<appSettings>
<add key="ApplicationContextPath" value="/TestApp" xdt:Transform="Replace[[R]]eplace" xdt:Locator="Match(key)"/>
</appSettings>
*Web.Release[[R]]elease.config
<appSettings>
<add key="ApplicationContextPath" value="/ReleaseApp[[R]]eleaseApp" xdt:Transform="Replace[[R]]eplace" xdt:Locator="Match(key)"/>
</appSettings>
====_Layout.cshtml====
@Scripts.Render[[R]]ender("~/bundles/jquery") @Scripts.Render[[R]]ender("~/bundles/bootstrap")
====実行結果====
<script src="/TestApp/Scripts/bootstrap.js"></script>
*本番
<script src="/ReleaseApp[[R]]eleaseApp/SalesMsReportSalesMs[[R]]eport/Scripts/jquery-3.3.1.js"></script> <script src="/ReleaseApp[[R]]eleaseApp/SalesMsReportSalesMs[[R]]eport/Scripts/bootstrap.js"></script>