本文整理汇总了C#中System.Web.HttpServerUtility.RelativePath方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServerUtility.RelativePath方法的具体用法?C# HttpServerUtility.RelativePath怎么用?C# HttpServerUtility.RelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpServerUtility
的用法示例。
在下文中一共展示了HttpServerUtility.RelativePath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterBundle
private void RegisterBundle(HttpServerUtility server, string bundle,
BundleType type,
params string[] files)
{
if (string.IsNullOrWhiteSpace(bundle))
throw new ArgumentNullException("bundle", "Cannot register an empty bundle");
var compressor = GetCompressor(type);
if (compressor.Cache.ContainsKey(bundle))
throw new ArgumentException("Bundle already registered");
if (files == null || files.Length == 0)
throw new ArgumentNullException("files", "No files to register");
var list = files.ToList();
if (server != null)
list = list.ConvertAll(file => server.MapPath(file));
if (RaiseErrorIfFileDoesNotExists)
{
var notFound = list.ToList().FindAll(file => !File.Exists(file));
if (notFound != null && notFound.Count > 0)
throw new ArgumentException(string.Format("Not able to find following files: {0}{1}", Environment.NewLine, string.Join(Environment.NewLine, notFound)));
}
if (IsDevMode)
compressor.Cache.Add(bundle, string.Join(Environment.NewLine, files.ToList().ConvertAll(path => string.Format(compressor.Tag, ResolvePath(path)))));
else
{
StringBuilder sb = new StringBuilder();
var yuiCompressor = compressor.GetCompressor();
list.ToList().ForEach(file =>
{
if (RaiseErrorIfFileDoesNotExists || (!RaiseErrorIfFileDoesNotExists && File.Exists(file)))
sb.Append(yuiCompressor.Compress(File.ReadAllText(file)));
});
if (imageCache.Count > 0)
imageCache.Keys.ToList().ForEach(key => sb.Replace(key, imageCache[key]));
var content = sb.ToString();
content = yuiCompressor.Compress(content); // double compression
var format = AddHash ? "{0}." + CreateHash(content) + ".{1}" : "{0}.{1}";
var path = Path.Combine(server.MapPath(compressor.Folder), string.Format(format, bundle, compressor.Extension));
WriteContent(path, content);
path = ResolvePath(server.RelativePath(path));
compressor.Cache.Add(bundle, string.Format(compressor.Tag, path));
}
}