小编Eri*_*ser的帖子

使用asp.net核心发布视图

在asp.net core 2.0项目中,我想强制发布Views,因为我在运行时需要它们.有线索吗?

asp.net-core

9
推荐指数
2
解决办法
5676
查看次数

使用asp.net核心身份将数据存储在cookie中

我正在使用ASP.NETEF端的核心身份我想在身份验证cookie中存储与用户相关的数据.

这就是我以前的做法ASP.NET 4.6(appcontext是要存储的数据):

public static void IdentitySignin(AppContext appContext, string providerKey = null, bool isPersistent = false)
{
    var claims = new List<Claim>();

    // create *required* claims
    claims.Add(new Claim(ClaimTypes.NameIdentifier, appContext.UserId.ToString()));
    claims.Add(new Claim(ClaimTypes.Name, appContext.UserName));

    // serialized AppUserState object
    claims.Add(new Claim("appcontext" + EZA.Store.AppContext.Version, appContext.ToString()));

    var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);

    // add to user here!
    AuthenticationManager.SignIn(new AuthenticationProperties()
    {
        AllowRefresh = true,
        IsPersistent = isPersistent,
        ExpiresUtc = DateTime.UtcNow.AddDays(7),
    }, identity);
}
Run Code Online (Sandbox Code Playgroud)

但现在我正在使用ASP.NET Identity,EF我找不到在cookie中存储一些数据的方法.

asp.net asp.net-mvc entity-framework asp.net-identity asp.net-core

6
推荐指数
2
解决办法
5693
查看次数

如何在Entity Framework Core中克隆实体?

我正在尝试使用SetValues方法克隆实体,但是我收到以下错误:

无法跟踪实体类型'TariffPeriod'的实例,因为已经跟踪了具有相同的{Id'}键值的另一个实例.附加现有实体时,请确保仅附加具有给定键值的一个实体实例.

这是代码:

var period2 = _tariffRepository.GetPeriodFull(period.GUID);
var period3 = new TariffPeriod();
_appDbContext.TariffPeriods.Add(period3);
_appDbContext.Entry(period3).CurrentValues.SetValues(period2);
Run Code Online (Sandbox Code Playgroud)

我看到错误是由于主键的值被复制到新实体中.那么,如何在没有密钥的情况下复制值?

谢谢你的帮助埃里克

entity-framework

4
推荐指数
3
解决办法
2196
查看次数