是HttpContext.Current.User全球ASAX不一样HttpContext.User中的一个操作方法?我为用户分配了一些角色,但他们似乎迷路了.
下面的代码显示了正在发生的事情.当用户登录时,两个断言都会被击中,首先是全局的asax,然后是操作方法.但是他们给出了不同的结果
首先这个:
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
// ... omitted some code to check user is authenticated
FormsIdentity identity = (FormsIdentity)HttpContext.Current.User.Identity;
string[] roles = new string[] { "admin", "user" };
HttpContext.Current.User =
new System.Security.Principal.GenericPrincipal(identity, roles);
Assert(HttpContext.User.IsInRole("admin"));
}
Run Code Online (Sandbox Code Playgroud)
然后在我的动作方法中:
public ActionResult Index()
{
bool isAdmin = HttpContext.User.IsInRole("admin");
Assert(isAdmin); // this fails, isAdmin is false
// ...
}
Run Code Online (Sandbox Code Playgroud)
我使用了以下资源
http://csharpdotnetfreak.blogspot.com/2009/02/formsauthentication-ticket-roles-aspnet.html
asp.net asp.net-mvc forms-authentication asp.net-mvc-3 asp.net-mvc-4
我目前正在设置jQuery验证插件,以便在我们的项目中使用.
默认情况下,会自动设置一些事件进行处理.即关注进/出,关键事件对所有输入进行火灾验证.我希望它只在单击提交按钮时触发.
这个功能似乎内置在插件中,这使得很难做到这一点(不修改插件代码,不是我想做的事).
我在插件代码原型方法中找到了eventDelegate函数调用:
$(this.currentForm)
.validateDelegate(":text, :password, :file, select, textarea", "focusin focusout keyup", delegate)
.validateDelegate(":radio, :checkbox, select, option", "click", delegate);
Run Code Online (Sandbox Code Playgroud)
当我从插件中删除这些行时,我得到了我的结果,但是我更愿意在插件之外做一些事情来实现这一点.
有人可以帮帮我吗?如果您需要更多详细信息,请告诉我们.我搜索谷歌几乎没有成功.
谢谢
编辑:我基本上尝试验证表单只有在触发提交事件时.默认情况下,每次输入控件中的焦点丢失时,插件都会进行验证.
在bash提示符下,我可以执行此副本
cp file.txt test1.txt
但是如果我尝试将file.txt复制到这样的几个文件中
cp file.txt test{2..4}.txt
Run Code Online (Sandbox Code Playgroud)
我收到错误
cp:target`test4.txt'不是目录