获取包含 C# 版本信息的捆绑包的当前 URL

本文关键字:URL 版本 信息 获取 包含 | 更新日期: 2023-09-27 18:34:53

我正在尝试获取我的一个捆绑包的 URL,其中包含 C# 中的版本信息。 我试图解决的问题是,我们必须将我们的一个页面托管在不同的服务器上的 iframe 中,并且我们需要向它传递它应该显示的任何自定义 CSS 的 URL。 我知道捆绑基本网址,但我不知道如何获取要传递到该页面的版本信息。

Styles.Url("~/css/someBundle").ToString();  //gets me the base url "/css/someBundle" in this case

我需要知道如何获取后面的部分 ?v={版本信息}

获取包含 C# 版本信息的捆绑包的当前 URL

根据从 Razor 文件中的@Scripts.Render(name)中查找定义,似乎还有一种Url方法:

public static class Scripts {
  [...]
  //
  // Summary:
  //     Returns a fingerprinted URL if the virtualPath is to a bundle, otherwise returns
  //     the resolve URL.
  //
  // Parameters:
  //   virtualPath:
  //     The virtual path.
  //
  // Returns:
  //     A System.Web.IHtmlString that represents the URL.
  public static IHtmlString Url(String virtualPath);
}

编辑:对此进行了快速测试:它确实返回了相对于站点根目录的路径,因此您需要转换为绝对URL。