Reputation: 7957
I've got a relatively large ASP.NET MVC4 web application. It has been accumulating static assets pretty rapidly, and it now has videos and large PDFs as part of the static assets in the Visual Studio project itself.
I currently deploy this to Azure's Websites service, straight from Visual Studio's publish feature.
I'd like to move these large static assets into Azure blob storage so that the Azure CDN service can serve them up for me. I've currently got a few larger files in blob storage, that I placed manually. I'm manually hard coding the URL to these CDN assets within my Razor templates. This definitely won't scale and is not manageable.
Is it possible to include Azure CDN as part of my Visual Studio workflow, in such a way that I can reference my project's assets using the same API, like @Url.Resource("~/public/pdf/large.pdf")
, and have that know to use the local file if I'm in debug mode, otherwise the CDN URL if this is in release mode? Also optionally manage uploading content to blob storage when I publish?
I've googled around but haven't come up with anything that looks this integrated.
Upvotes: 1
Views: 1122
Reputation: 2610
This article here shows how use Powershell to do it for your content and script files. It would be fairly easy to manipulate the provided script to point to another folder where your static files are and meet your needs more closely. You could then call the script during your build pipeline.
For managing the reference to your projects assets while in Debug vs Release I would probably create a custom MVC Helper Function that wraps @Url.Resource() and reads the current configuration and sets the correct url.
In sudo code it would be somthing like this:
public static class MyHeleprs
{
public static MvcHtmlString MyResource(this HtmlHelper htmlHelper,
string resourceString)
{
#if(DEBUG)
return MvcHtmlString.Create(Url.Resource("~/public/" + resourceString));
#else
return MvcHtmlString.Create("<path_to_cdn>/" + resourceString);
#endif
}
}
And to use it:
@Html.MyResource("/pdf/large.pdf");
Upvotes: 2