我试图在我的应用程序中使用相同的用户阻止多次登录.
我的想法是在用户登录时更新安全标记并将其添加为Claim,然后在每个请求中将Cookie中的标记与数据库中的标记进行比较.这就是我实现的方式:
public virtual async Task<ActionResult> Login([Bind(Include = "Email,Password,RememberMe")] LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
SignInStatus result =
await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, false);
switch (result)
{
case SignInStatus.Success:
var user = UserManager.FindByEmail(model.Email);
var id = user.Id;
UserManager.UpdateSecurityStamp(user.Id);
var securityStamp = UserManager.FindByEmail(model.Email).SecurityStamp;
UserManager.AddClaim(id, new Claim("SecurityStamp", securityStamp));
Run Code Online (Sandbox Code Playgroud)
然后在身份验证配置中我添加了
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = ctx =>
{
var ret = Task.Run(() =>
{
Claim claim = …Run Code Online (Sandbox Code Playgroud) 我有一个在ASP.NET Panel中放置的gridview.面板和Gridview都在UpdatePanel中.gridview中有一列导致部分PostBacks.我想在这些回发上保持Panel Scroll位置.有什么办法吗?问候.
假设有一个ASP.NET MVC应用程序使用Entity Framework 6,代码优先方法和StructureMap作为IoC.
它还使用工作单元模式.以下是代码:
域类
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
IUnitOfWork和DbContext:
public interface IUnitOfWork
{
IDbSet<TEntity> Set<TEntity>() where TEntity : class;
int SaveChanges();
}
public class Sample07Context : DbContext, IUnitOfWork
{
public DbSet<Product> Products { set; get; }
#region IUnitOfWork Members
public new IDbSet<TEntity> Set<TEntity>() where TEntity : class
{
return base.Set<TEntity>();
}
#endregion
}
Run Code Online (Sandbox Code Playgroud)
服务类中的业务逻辑:
public interface …Run Code Online (Sandbox Code Playgroud) c# structuremap asp.net-mvc entity-framework dependency-injection
我如何模拟AsNoTracking方法?
在下面的示例中,DbContext已注入服务类.如果我从GetOrderedProducts方法中删除AsNoTracking扩展方法,但是AsNoTracking测试失败,因为它返回null,它工作正常.我也尝试过模拟AsNoTracking以返回正确的值,但它没有用.
public interface IUnitOfWork
{
IDbSet<TEntity> Set<TEntity>() where TEntity : class;
int SaveAllChanges();
}
public class Entites : DbContext, IUnitOfWork
{
public virtual DbSet<Product> Products { get; set; } // This is virtual because Moq needs to override the behaviour
public new virtual IDbSet<TEntity> Set<TEntity>() where TEntity : class // This is virtual because Moq needs to override the behaviour
{
return base.Set<TEntity>();
}
public int SaveAllChanges()
{
return base.SaveChanges();
}
}
public class ProductService
{
private readonly IDbSet<Product> …Run Code Online (Sandbox Code Playgroud) 如何使用c#捕获特定的异常?
在我的数据库中,某些列上有唯一索引.
当用户插入重复记录时,抛出此异常:
无法在对象'dbo中插入重复的键行.BillIdentity'具有独特的指数'IX _BillIdentity'.该语句已终止.
我怎么能抓住这个例外?
目前我正在检查使用此代码:
catch (Exception ex) {
if (ex.Message.Contains("Cannot insert duplicate key row in object 'dbo._BillIdentity' with unique index 'IX__BillIdentity")) {
string ScriptKey = "$(function() {ShowMessage('Error');});";
ScriptManager.RegisterStartupScript(Page, GetType(), "script", ScriptKey, true);
}
}
Run Code Online (Sandbox Code Playgroud)
我觉得它的味道很难闻.
有没有更好的方法?
我无法在此jquery ui对话框中添加按钮.如果可能的话请举个例子.谢谢.
<script type="text/javascript">
$(document).ready(function () {
//setup new person dialog
$('#dialog2').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: 'auto',
width: '1000',
autoOpen: false,
modal: true,
position: 'top',
draggable: false,
title: "?????? ???????",
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
$('#viewfaktor').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: 'auto',
width: '1000',
autoOpen: false,
modal: true,
position: 'top',
draggable: true,
title: "?????? ???? ???",
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
$('#msgBox').dialog({
autoResize: true,
show: "clip",
hide: "clip",
height: …Run Code Online (Sandbox Code Playgroud) 我想在鼠标位置打开JQuery UI对话框.我的代码有什么问题?
<script type="text/javascript">
$(document).ready(function () {
var x;
var y;
$(document).mousemove(function (e) {
x = e.pageX;
y = e.pageY;
});
$("#d").dialog({
autoOpen: false,
show: "blind",
hide: "explode",
position: [x, y]
});
$("#c").bind("mouseover", function () {
$("#d").dialog('open'); // open
});
$("#c").bind("mouseleave", function () {
$("#d").dialog('close'); // open
});
});
</script>
Run Code Online (Sandbox Code Playgroud) 是否有任何powershell脚本可以在没有开放视觉工作室的情况下构建visual studio项目?
我尝试检查ASP.NET CheckboxList中的多个值,但我不能.
我写 :
chkApplications.SelectedValue = 2;
chkApplications.SelectedValue = 6;
Run Code Online (Sandbox Code Playgroud)
但它只选择值为'6'的项目有
什么问题?
c# ×4
jquery ×3
asp.net ×2
asp.net-mvc ×2
jquery-ui ×2
checkboxlist ×1
cookies ×1
css ×1
html ×1
mocking ×1
moq ×1
position ×1
postback ×1
powershell ×1
refactoring ×1
scroll ×1
structuremap ×1
unit-testing ×1
updatepanel ×1