我正在使用新的ASP.NET捆绑功能,似乎无法让我的自定义订单工作.这是我的JS文件:
bootstrap.js
bootstrap.min.js
jquery-1.7.2.intellisense.js
jquery-1.7.2.js
jquery-1.7.2.min.js
jquery-ui-1.8.19.js
jquery-ui-1.8.19.min.js
jquery.unobtrusive-ajax.js
jquery.unobtrusive-ajax.min.js
Run Code Online (Sandbox Code Playgroud)
我想捆绑器在所有jQuery文件之前输出boostrap*.js.我理解在内部捆绑器会在顶部对jQuery文件进行排序,所以我试图覆盖逻辑但没有成功:
var bootstrapOrdering = new BundleFileSetOrdering("bootstrap");
bootstrapOrdering.Files.Add("bootstrap*.js");
bootstrapOrdering.Files.Add("jquery*.js");
BundleTable.Bundles.FileSetOrderList.Add(bootstrapOrdering);
Run Code Online (Sandbox Code Playgroud)
注意:如果可能的话,我更愿意使用通配符来覆盖所有情况而不指定代码中的所有文件.
有谁知道我可以申请定制订单?
谢谢
所以MVC 4引入了脚本和样式捆绑.这允许:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/mobile").Include(
"~/Scripts/jquery.mobile-*"));
Run Code Online (Sandbox Code Playgroud)
然后在这样的剃刀视图中使用:
@Scripts.Render("~/bundles/mobile")
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么我要输入"~/bundles/mobile"?是否有办法让intellisence有一个强类型对象来接收?否则我必须去查找以确保我称之为同样的事情.
我想做这样的事情:(我知道这不会以这种方式编译,这只是一个例子)
public static void RegisterBundles(BundleCollection bundles)
{
Bundle mobile = new Bundle("mobile");
mobile.AddFile("w/e")
bundles.Add(mobile);
//in page:
@Scripts.Render(BundleConfig.mobile)
Run Code Online (Sandbox Code Playgroud)
或那些影响的东西.
编辑:答案很简单.正如@Hao Kung指出的@Styles.Render只是需要一个URL字符串路径.我创建了一个类来保存.
public class bundles
{
#region Javascript
public static string scripts = "~/bundles/scripts";
...
#endregion
#region CSS
public static string css = "~/Content/css";
public static string jqueryUi = "~/Content/themes/base/css";
...
#endregion
}
Run Code Online (Sandbox Code Playgroud)
在任何页面,你只需要做
@Styles.Render(bundles.jqueryUi)
Run Code Online (Sandbox Code Playgroud)
你有它.你需要付出额外的努力,但至少它现在是强力打字的.
strong-typing asp.net-mvc-4 bundling-and-minification asp.net-optimization
我正在使用asp.net捆绑/缩小并将所有内容放在bundle.config中,如下所示:
<styleBundle path="~/css/css">
<include path="~/css/bootstrap.css" />
<include path="~/css/flexslider.css" />
<include path="~/css/font-awesome.css" />
<include path="~/css/Site.css" />
<include path="~/css/orange.css" />
</styleBundle>
Run Code Online (Sandbox Code Playgroud)
但是我想从CDN使用bootstrap.css:
//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css
Run Code Online (Sandbox Code Playgroud)
那么我们怎么能在bundle.config中做到这一点呢?
昨晚,我决定尝试将SignalR应用到我的应用程序,因为我使用MVC 5,我不得不使用SignalR的2.0 beta.
哦,男孩,什么时间.昨晚,微软还决定推出所有mvc 5相关软件包的rc1,并且更新打破了一些问题 - 主要是在beta2模板中的帐户控制器中.
public AccountController()
{
IdentityStore = new IdentityStoreManager();
AuthenticationManager = new IdentityAuthenticationManager(IdentityStore);
}
public AccountController(IdentityStoreManager storeManager, IdentityAuthenticationManager authManager)
{
IdentityStore = storeManager;
AuthenticationManager = authManager;
}
public IdentityStoreManager IdentityStore { get; private set; }
public IdentityAuthenticationManager AuthenticationManager { get; private set; }
Run Code Online (Sandbox Code Playgroud)
IdentityStoreManager并且IdentityAuthenticationManager不再被认可.
有没有人成功迁移到rc1了?我找不到MS的任何文档或更新的模板.
我正在尝试实现密码重置功能。我使用 ASP.NET 身份。
我正在使用UserManager.GetConfirmationToken返回这样的令牌:
UW/cj4xUj08kiGCntnWs7z1eUcWlyfNczH5IZfvf0ScTi4L1jgdkkus/Zb5ROJOWb%2b1XAVRSiBUvVGnESfEyauDDa4u%2bPDUH6D/CIpwPcFYRvLi%2b%2bq6f%2bRIhKHRTsGMV0y8lXpSZ5V qySWGSSaW9kofGage/IjW4HrvONeETA4Szov3u7HgmqEUf0yzgivJ0
然后,我编写 URL 并通过电子邮件将其发送给注册用户。激活账户的url是这样的:
http://localhost:4322/Account/Confirm/UW/cj4xUj08kiGCntnWs7z1eUcWlyfNczH5IZfvf0ScTi4L1jgdkkus/Zb5ROJOWb%2b1XAVRSiBUvVGnESfEyauDDa4u%2bPDUH6D/CIpwPcFYRvLi%2b%2bq6f%2bRIhKHRTsGMV0y8lXpSZ5VqySWGSSaW9kofGage/IjW4HrvONeEtA4Szov3u7HgmqEUf0yzgivJ0
Run Code Online (Sandbox Code Playgroud)
当我点击时,出现这个错误:
Error HTTP 404.11 - Double escape sequence issue
asp.net identity asp.net-membership asp.net-mvc-5 asp.net-identity
根据Scott Guthrie早些时候读过的一篇文章和Mads Kristensen发布的视频,我应该能够通过替换它来自动捆绑/缩小ASP.net MVC 4:
<link href="Styles/reset.css" rel="stylesheet" type="text/css" />
<link href="Styles/normalize.css" rel="stylesheet" type="text/css" />
<link href="Styles/styles.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="Scripts/jquery-validation.min.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
有了这个:
<link href="Styles/css" rel="stylesheet" type="text/css" />
<script src="Scripts/js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
我尝试过针对.Net 4.0和4.5,它似乎没有什么区别.我收到404错误,链接和脚本标记从不指向捆绑的资源.
这个功能是否从最终版本中删除了?
我想将此功能用于"主题".
这就是我最终实现的方式.希望它有意义......
/// <summary>
/// Render stylesheets HTML for the given theme. Utilizes System.Web.Optimization for bundling and minification
/// </summary>
/// <param name="themeName">Name of theme</param>
/// <returns>HtmlString containing link elements</returns>
public static IHtmlString RenderThemeStyles(string …Run Code Online (Sandbox Code Playgroud) asp.net-mvc asp.net-mvc-4 bundling-and-minification asp.net-optimization
我正在尝试获取IList<ApplicationRole>用户当前注册的角色.
现在在Usermanager类中,我看到有一个函数调用IList<String> usersRoles = userManager.GetRoles(id);但它只是将Role的名称作为字符串返回.这并不能帮助我,我需要的id,name和description中的作用.
我怎样才能进行类似的调用但是收到applicationRole而不是字符串?
这是我的模特:
public class ApplicationRole : IdentityRole
{
[Display(Name = "Description")]
[StringLength(100, MinimumLength = 5)]
public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc user-roles asp.net-mvc-5 asp.net-identity
在MVC 4中,我可以使用@ Styles.Render("〜/ Content/css")调用一组CSS文件定义BundleConfig文件,而不是直接调用CSS.
什么时候应该使用bundle而不是直接调用文件?当我们有各种CSS文件来简化代码时,我清楚地理解它.但是如果有一个CSS文件,我们应该使用一个包还是直接调用它?
我正在使用Visual Studio 2012和MVC 4,在我的_Layout.cshtml中,我有以下内容:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/jqgrid")
@RenderSection("head", required: false)
</head>
<body>
@RenderBody()
@RenderSection("scripts", required: false)
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在BundleConfig.cs中我有
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqgrid").Include(
"~/Scripts/jquery.jqGrid.min.js"));
}
}
Run Code Online (Sandbox Code Playgroud)
我已经三重检查,我的脚本文件夹确实包含jquery.jqGrid.min.js,但它没有包括在内.
我的Html头看起来像:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link href="/Viper/Content/css" rel="stylesheet"/>
<script src="/Viper/Scripts/jquery-1.8.1.js"></script>
<script src="/Viper/Scripts/jquery-ui-1.8.23.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
任何想法为什么没有添加?
嗨我目前正在尝试编写一个MVC5应用程序,该应用程序能够在使用facebook或twitter授权后存储为用户收到的令牌.
我想将它存储在数据库而不是cookie中,并将其用于任何未来的API请求和用户进行的登录尝试,这样每次他们尝试登录时都不会提示他们使用facebook或twitter进行授权.方法或尝试访问个人资料信息.
查看成员资格数据库,我可以看到有一个名为AspNetTokens的表没有被使用 - 所以有什么我错过了可以使用它的地方吗?