【发布时间】:2017-11-09 14:02:23
【问题描述】:
asp-append-version="true" 这应该将版本附加到脚本。使用 .net core 1.1 它工作得很好。最近升级到 2.0 版,它不再工作。任何想法为什么?
【问题讨论】:
标签: asp.net-core asp.net-core-2.0
asp-append-version="true" 这应该将版本附加到脚本。使用 .net core 1.1 它工作得很好。最近升级到 2.0 版,它不再工作。任何想法为什么?
【问题讨论】:
标签: asp.net-core asp.net-core-2.0
https://github.com/MarkPieszak/aspnetcore-angular2-universal/issues/471
基本上你现在需要
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
为了方便起见,您可以在 Views 文件夹下创建一个全局 _ViewImports.cshtml 文件,然后将该行放入其中,它将将该行应用于所有 View 页面。
【讨论】:
在 MVC 中,我们可以通过维护配置值来进行版本控制,然后使用公共类将版本附加到 JS 和 CSS 参考中。
CS:
public static class StaticFileHelper
{
static string staticVersion;
static StaticFileHelper()
{
staticVersion = System.Configuration.ConfigurationManager.AppSettings["JSVersioning"];
}
public static string StaticFile(this UrlHelper html, string filename)
{
var virtualPath = ReleaseVirtualPath(filename);
var root = html.RequestContext.HttpContext.Request.ApplicationPath;
if (root.Length > 1)
{
virtualPath = root + virtualPath;
}
return virtualPath;
}
}
【讨论】:
在这种情况下,我提出了这个解决方案
<link rel="stylesheet" type="text/css" href="\css\custom.css?v=@Generator.RandomStringGenerator(9)">
所以我的随机生成器正在为版本生成不同的字符串,然后我再也不会遇到这种情况了。我还为感兴趣的人分享随机字符串生成器。
private static Random random = new Random();
public static string RandomStringGenerator(int length)
{
const string chars = "abcdefghijklmnopqrstuwxyz0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
【讨论】: