相关疑难解决方法(0)

如何将捆绑和缩小的文件上载到Windows Azure CDN

我正在使用ASP.NET MVC 4捆绑和缩小Microsoft.AspNet.Web.Optimization命名空间中的功能(例如@Styles.Render("~/content/static/css")).

我想将它与Windows Azure CDN结合使用.

我考虑编写自定义,BundleTransform但内容尚未优化.

我还研究了在运行时解析和上传优化的流,但这对我来说就像是一个黑客,我真的不喜欢它:

@StylesCdn.Render(Url.AbsoluteContent(
    Styles.Url("~/content/static/css").ToString()
    ));

public static IHtmlString Render(string absolutePath)
{
    // get the version hash
    string versionHash = HttpUtility.ParseQueryString(
        new Uri(absolutePath).Query
        ).Get("v");

    // only parse and upload to CDN if version hash is different
    if (versionHash != _versionHash)
    {
        _versionHash = versionHash;

        WebClient client = new WebClient();
        Stream stream = client.OpenRead(absolutePath);

        UploadStreamToAzureCdn(stream);
    }

    var styleSheetLink = String.Format(
        "<link href=\"{0}://{1}/{2}/{3}?v={4}\" rel=\"stylesheet\" type=\"text/css\" />",
        cdnEndpointProtocol, cdnEndpointUrl, cdnContainer, cdnCssFileName, versionHash …
Run Code Online (Sandbox Code Playgroud)

cdn azure asp.net-mvc-4 bundling-and-minification asp.net-optimization

27
推荐指数
2
解决办法
7463
查看次数