I would like to access my host and build my bundles. I know it is not straight to access httpcontext in Application_start.
Can you advise any other work around to find the Request.url.host
in RegisterBundles
Method
Global.asax
protected void Application_Start()
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
BundleConfig.asax
public static string host { get; set; }
public static string siteCssFileName { get; set; }
public static void RegisterBundles(BundleCollection bundles)
{
host = "~";
if (System.Web.HttpContext.Current.Request.Url.Host.Contains("local"))
host = "http://localhost:xxx";
else
host=Request.url.host;
bundles.Add(new StyleBundle("~/Content/jQuery/ui/css")
.Include(host+"/css/jQuery/hro-0079c1/jquery-ui-1.8.11.custom.css"));
}
Since I could not get my Request object in application start event, I have choose the below approach to achieve my task. All that I wanted to know was my host in app start event.
<add key="cdnReference" value="http://localhost:xxxx/" />
cdnHost = ConfigurationManager.AppSettings["cdnReference"];