从一个全新的ASP.NET MVC 4 Beta Web应用程序,我正在重新安排我的文件夹以匹配Rob Conery的VidPub.Web示例
具体来说,这意味着内容的最终目录结构如下所示
VidPub.Web | ---Public | |---Images |--- *.png |---javascripts |--- *.js |---stylesheets |----themes |---base |--- images |--- *.css |----site.css
但是,当我更改以下行时 _Layout.cshtml
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Content/css")"
rel="stylesheet"
type="text/css" />
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Content/themes/base/css")"
rel="stylesheet"
type="text/css" />
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Scripts/js")"></script>
Run Code Online (Sandbox Code Playgroud)
至
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Public/stylesheets/css")"
rel="stylesheet"
type="text/css" />
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Public/stylesheets/themes/base/css")"
rel="stylesheet"
type="text/css" />
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
"~/Public/javascripts/js")"></script>
Run Code Online (Sandbox Code Playgroud)
在最终的HTML中,我最终没有任何结果.
<link rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" />
<script></script>
Run Code Online (Sandbox Code Playgroud)
为什么不在新位置拾取文件?
我需要能够暂时禁用单个请求的捆绑和缩小,以便调试JavaScript和CSS问题.我想在运行时通过向QueryString添加一个参数来执行此操作,如此...
http://domain.com/page?DisableOptimizations=true
Run Code Online (Sandbox Code Playgroud)
这是我正在考虑的方法.
protected void Application_BeginRequest(object sender, EventArgs e)
{
// Enable for every request
BundleTable.EnableOptimizations = true;
// Disable for requests that explicitly request it
bool disable;
bool.TryParse(Context.Request.QueryString["DisableOptimizations"], out disable);
if (disable)
{
BundleTable.EnableOptimizations = false;
}
}
Run Code Online (Sandbox Code Playgroud)
c# asp.net asp.net-mvc bundling-and-minification asp.net-optimization
我正在构建一个新的ASP.NET MVC 5项目,我希望在9月左右发布.我需要选择一个会员系统,但我现在很困惑我应该采取哪个方向.目前的SimpleMembership运行良好,但显然与即将推出的ASP.NET身份不兼容.另一方面,ASP.NET身份是绝对新的,没有文档,可以随时更改.最后,似乎这里使用了基于字符串的ID,与SimpleMembership支持的基于整数的ID相比,这似乎是非常不必要的开销.我可以选择一种好的,面向未来的方式吗?
我想知道是否有人可以帮助我使用MVC 4附带的新优化命名空间进行捆绑和缩小.我有一个Multitenant应用程序,我想根据每个用户的设置决定应该加载哪些js文件.一种方法是预先创建所有捆绑包并根据用户的设置更改resolvebundleurl的虚拟路径,但这感觉不是真正正确的方式.另外,我在基于用户设置的cshtml视图中有动态css,我想在运行时缩小它.
有什么建议?在其他问题中我也看到很多反应来检查Requestreduce,但它们都来自同一个用户.
处理这两种情况的最佳方法是什么?
提前致谢!
asp.net optimization bundle asp.net-mvc-4 asp.net-optimization
我正在MVC4中实现捆绑和缩小支持并进行设置,以便它可以自动编译我的Bootstrap .less文件.我在BundleConfig.cs文件中有以下代码
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
// base bundles that come with MVC 4
var bootstrapBundle = new Bundle("~/bundles/bootstrap").Include("~/Content/less/bootstrap.less");
bootstrapBundle.Transforms.Add(new TwitterBootstrapLessTransform());
bootstrapBundle.Transforms.Add(new CssMinify());
bundles.Add(bootstrapBundle);
}
}
Run Code Online (Sandbox Code Playgroud)
TwitterBootsrapLessTransform如下所示(由于需要将sub .less文件导入dotLess,因此比我想要的更复杂)
public class TwitterBootstrapLessTransform : IBundleTransform
{
public static string BundlePath { get; private set; }
public void Process(BundleContext context, BundleResponse response)
{
setBasePath(context);
var config = new DotlessConfiguration(DotlessConfiguration.GetDefault());
config.LessSource = typeof(TwitterBootstrapLessMinifyBundleFileReader);
response.Content = Less.Parse(response.Content, config);
response.ContentType = "text/css";
}
private void setBasePath(BundleContext context)
{
BundlePath = …
Run Code Online (Sandbox Code Playgroud) asp.net-mvc-4 bundling-and-minification asp.net-optimization
我只是尝试ASP.NET MVC 4,但我无法弄清楚如何禁用Javascript/CSS缩小功能.特别是对于开发环境,这将有助于调试.我想这将是web.config中的一个开关,但由于ASP.NET MVC 4目前仍处于测试阶段,因此实际上没有太多信息.如果有人可以帮助或指向正确的博客文章等,将不胜感激.
生成的捆绑文件放在哪里?
bundles.Add(new ScriptBundle("~/bundles/jqueryall")
.IncludeDirectory("~/scripts/", "*.js", true)
Run Code Online (Sandbox Code Playgroud) asp.net-mvc-4 bundling-and-minification asp.net-optimization
如何在Microsoft.AspNet.Identity.UserManager上设置AllowOnlyAlphanumericUserNames标志,以便UserValidator将允许非字母数字用户名?
我想定义一个这样的包:
bundles.Add(
new StyleBundle("~/style.css").Include(
//...
));
Run Code Online (Sandbox Code Playgroud)
如果捆绑包名称只是"~/style"
这样,但是文件扩展名它总是返回404.我怀疑服务器在驱动器上搜索CSS和JS文件并忽略捆绑系统,但是我找不到其他人正在尝试在包名称中包含文件扩展名.这可能没有像URL重写这样的东西吗?
asp.net-mvc asp.net-mvc-4 bundling-and-minification asp.net-optimization
每次部署MVC Web应用程序时,我的服务器都必须重新缓存所有js和css包.
因此,部署后第一个视图渲染可能需要几秒钟.
有没有办法预先缓存包?毕竟,文件在编译时是静态的.
asp.net ×5
asp.net-mvc ×2
c# ×2
identity ×2
bundle ×1
css ×1
javascript ×1
membership ×1
minify ×1
optimization ×1