Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ';';Id';在'上的属性;识别码'4';无法设置为';System.Int32';价值_C#_.net - Fatal编程技术网

C# ';';Id';在'上的属性;识别码'4';无法设置为';System.Int32';价值

C# ';';Id';在'上的属性;识别码'4';无法设置为';System.Int32';价值,c#,.net,C#,.net,我在尝试登录sql数据库中的电子邮件时遇到此错误 'IdentityUser'4'上的'Id'属性无法设置为 “System.Int32”值。必须将此属性设置为非空值 类型为'System.String' 正如我在错误中看到的,Identityuser这个词中有一个不寻常的撇号,我不知道这个数字4是从哪里来的。每个测试用例都是一样的。Im使用帐户控制器的标识示例库。使用.net4.5框架 这是我的账户控制方法。我已经提到了我从哪里得到的错误 [HttpPost]

我在尝试登录sql数据库中的电子邮件时遇到此错误

'IdentityUser'4'上的'Id'属性无法设置为 “System.Int32”值。必须将此属性设置为非空值 类型为'System.String'

正如我在错误中看到的,Identityuser这个词中有一个不寻常的撇号,我不知道这个数字4是从哪里来的。每个测试用例都是一样的。Im使用帐户控制器的标识示例库。使用.net4.5框架

这是我的账户控制方法。我已经提到了我从哪里得到的错误

        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

        // This doesn't count login failures towards lockout only two factor authentication
        // To enable password failures to trigger lockout, change to shouldLockout: true
        
        var user = SignInManager.UserManager.Users.Where(u => u.Email == model.Email).FirstOrDefault();
        var result = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, model.RememberMe, shouldLockout: false); //getting error here

        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
        }
    }
[HttpPost]
[异名]
[ValidateAntiForgeryToken]
公共异步任务登录(LoginView模型,字符串返回URL)
{
如果(!ModelState.IsValid)
{
返回视图(模型);
}
//这不包括登录失败和仅锁定两因素身份验证
//要启用密码故障触发锁定,请更改为shouldLockout:true
var user=SignInManager.UserManager.Users.Where(u=>u.Email==model.Email).FirstOrDefault();
var result=await-SignInManager.PasswordSignInAsync(user.UserName,model.Password,model.RememberMe,shouldllockout:false);//此处获取错误
开关(结果)
{
案例标志状态成功:
返回重定向到本地(returnUrl);
案例标志状态锁定输出:
返回视图(“锁定”);
案例标志状态。要求验证:
return RedirectToAction(“SendCode”,new{ReturnUrl=ReturnUrl,RememberMe=model.RememberMe});
案例信号状态故障:
违约:
AddModelError(“,”登录尝试无效“);
返回视图(模型);
}
}
这是我的身份模型

using GiftSmart.DataModel;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Data.Entity;
using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;

namespace IdentitySample.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            // Add custom user claims here
            return userIdentity;
        }
    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("GiftSmartContext", throwIfV1Schema: false)
        {
        }

        static ApplicationDbContext()
        {
            // Set the database intializer which is run once during application start
            // This seeds the database with admin user credentials and admin role
            //Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
            //Database.SetInitializer<ApplicationDbContext>(new DropCreateDatabaseIfModelChanges<ApplicationDbContext>());
            Database.SetInitializer(new CreateDatabaseIfNotExists<GiftSmartContext>());
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }

        public static string GetConnectionString()
        {

            return "Data Source=CL-KASUNP\\SQLEXPRESS;Initial Catalog=giftsmart_live;Integrated Security=True;";

        }
    }
}
使用GiftSmart.DataModel;
使用Microsoft.AspNet.Identity;
使用Microsoft.AspNet.Identity.EntityFramework;
使用制度;
使用System.Data.Entity;
使用System.Security.Claims;
使用System.Threading.Tasks;
使用System.Web;
名称空间标识sample.Models
{
//您可以通过向ApplicationUser类添加更多属性来为用户添加配置文件数据,请访问http://go.microsoft.com/fwlink/?LinkID=317594 了解更多。
公共类应用程序用户:IdentityUser
{
公共异步任务GenerateUserIdentityAsync(用户管理器)
{
//注意authenticationType必须与CookieAuthenticationOptions.authenticationType中定义的类型匹配
var userIdentity=wait manager.CreateIdentityAsync(这是DefaultAuthenticationTypes.ApplicationOkie);
//在此处添加自定义用户声明
返回用户身份;
}
}
公共类ApplicationDbContext:IdentityDbContext
{
公共应用程序上下文()
:base(“GiftSmartContext”,throwifvv1schema:false)
{
}
静态ApplicationDbContext()
{
//设置在应用程序启动期间运行一次的数据库初始化器
//这将使用管理员用户凭据和管理员角色为数据库种子
//SetInitializer(新的ApplicationBinInitializer());
//SetInitializer(新的DropCreateDatabaseIfModelChanges());
SetInitializer(新的CreateDatabaseIfNotExists());
}
公共静态应用程序上下文创建()
{
返回新的ApplicationDbContext();
}
公共静态字符串GetConnectionString()
{
返回“数据源=CL-kasump\\SQLEXPRESS;初始目录=giftsmart_live;集成安全性=True;”;
}
}
}

检查这个:@johhan85因为在这个问题中有一个由开发人员定义的branchIdentity类。但在我的例子中,没有identity user类。它是来自identitySample库的一个bulit类