如果您的软件包大小过大,可能会受益于部署独立文件,而不是一个大的单一软件包文件。至少在Visual Studio 2012中,发布向导现在具有以下部署选项:
- Web Deploy(我鼓励您使用这个)
- Web Deploy Package
- FTP
- 文件系统
据我所知,Web Deploy比较源文件和目标文件,物理传输仅有不同的文件(它可能会比较文件哈希,但我不知道内部情况)。
无论如何,我将尝试提供更多信息来解决您的问题:
我们网站的80%在HTTPS环境下运行。在blob存储中访问图像是否会引入跨脚本问题?
Gaurav Mantri已经回答了这个问题,但为了提供更多最近的信息,现在支持通过HTTPS访问Azure CDN,因此您可以避免混合内容消息。(仍在等待支持自定义域/SSL证书(UserVoice请求与最新信息
here)。
顺便提一下,使用无协议约定(
://{domain}/{relative path}
),浏览器将使用与基础文档完全相同的HTTP或HTTPS协议。
我很难想象如何使用目录命名约定将文件上传到Blob容器(从VS2010 + Azure SDK),以便我不需要重写数千个路径引用? 我知道目录在Blob容器中是一个抽象概念,但我可以在代码中使用正斜杠来编写文件以模仿它。 很明显,在Visual Studio中上传之前,Windows不允许我这样做。
将静态文件同步到Blob
同步静态文件的一个可脚本化选项是AZCopy工具。
另一种选择是这个powershell脚本(更多信息请参见帖子),总结如下:
Does the initial setup:
$context = New-AzureStorageContext `
-StorageAccountName $StorageAccount `
-StorageAccountKey (Get-AzureStorageKey $StorageAccount).Primary
Enumerates all local files on .\Content and .\Scripts:
$files = (ls -Path $ProjectPath\Content -File -Recurse) + (ls -Path $ProjectPath\Scripts -File -Recurse)
...and uploads each file on a loop:
foreach ($file in $files)
{
$blobFileName = (Resolve-Path $file.FullName -Relative).TrimStart('.')
$contentType = switch ([System.IO.Path]::GetExtension($file))
{
".png" {"image/png"}
".css" {"text/css"}
".js" {"text/javascript"}
default {"application/octet-stream"}
}
Set-AzureStorageBlobContent `
-Container $StorageContainer `
-Context $context `
-File $file.FullName `
-Blob $blobFileName `
-Properties @{ContentType=$contentType} `
-Force
}
引用CDN资源
另一个要解决的问题是如何引用CDN上的文件,而不是相对路径的文件。有不同的解决方案,大多数使用辅助函数将适当的前缀注入到相对路径中(以下问题的一些答案可以帮助您:ASP.NET MVC 相对路径)。
我建议采用集中式的方式构建CDN资产URL,甚至可以实现某种缓存清除器(为此,您需要在Azure CDN上启用查询字符串参数):
Razor:
<img src="@Helper.ToCdnUrl("images/asset1.png")">
辅助方法:
public static string ToCdnUrl(string relativePath)
{
string prefix = ConfigurationManager.AppSettings["CdnUrlBasePath"];
string sufix = ConfigurationManager.AppSettings["StaticFilesVersion"];
return String.concat(prefix, relativePath, "?v=", sufix);
}
应用程序设置:
<add key="CdnUrlBasePath" value="://<yourCDNName>.vo.msecnd.net/" />
<add key="StaticFilesVersion" value="1.01" />
渲染的 HTML:
<img src="://<yourCDNName>.vo.msecnd.net/images/asset1.png?v=1.01">