DataContext初始化出现错误

时间:2019-01-14 16:27:18

标签: asp.net-mvc asp.net-core-2.1

我正在尝试创建自己的自定义注册。哪个有效

但是当我尝试初始化dataContext时添加存储过程时,它将引发错误。这是我的代码

namespace Login.Controllers.Work
{
    public class PostController : Controller
    {

        private readonly UserManager<ApplicationUser> _userManager;
        private readonly DataContext _context;

        private readonly SignInManager<ApplicationUser> _signInManager;
        private readonly IEmailSender _emailSender;
        private readonly ILogger _logger;

        public PostController(DataContext context, UserManager<ApplicationUser> userManager,  SignInManager<ApplicationUser> signInManager, IEmailSender emailSender,    ILogger<AccountsController> logger )
        {
            _userManager = userManager;
            _signInManager = signInManager;
            _emailSender = emailSender;
            _logger = logger;
           _context = context;
        }

当我添加DataContext上下文并将其在下面设置为_context = context;我的Ajax查询出现错误500

错误消息是

HTTP500:服务器错误-服务器遇到意外状况,阻止其满足请求。 (XHR)POST-https://localhost:44345/SignUp

这是怎么了?

谢谢

1 个答案:

答案 0 :(得分:0)

我忘记将服务注册添加到startup.cs文件中

    services.AddDbContext<DataContext>(options => options.UseSqlServer(connection));

现在可以了 谢谢