本文介绍了如何在当前Web请求期间解决未经处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个数据库作为Accountuser,而表格作为App目录文件夹上的LogOn。



在我的浏览器上,当我尝试注册一个电子邮件和密码时,我总是得到这个例外。我需要你的帮助来解决这个问题









模特支持自创建数据库以来,'GuestBookContext'上下文已更改。请考虑使用代码优先迁移来更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269)。

描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的起源的更多信息。



异常详细信息:System.InvalidOperationException:支持'GuestBookContext'上下文的模型自数据库创建以来已更改。考虑使用Code First Migrations更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269)。



源错误:

i created a database as Accountuser , while the table as LogOn on the App directory folder.

on my browser, when i try to register a email and password , i always get this exception. i need your help to resolve this




The model backing the 'GuestBookContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model backing the 'GuestBookContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

Source Error:

Line 36:                 if (ModelState.IsValid)
Line 37:                 {
Line 38:                     var CreUserFind = _db.accountdetails.Find(details.NEmail);
Line 39:                     if (CreUserFind != null)
Line 40:                     {



源文件:c:\用户\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ b>我尝试了什么:




Source File: c:\Users\D doll\Documents\Visual Studio 2012\Projects\GuestBook\GuestBook\Controllers\AccountUserController.cs Line: 38

What I have tried:

using GuestBook.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace GuestBook.Controllers
{
    public class AccountUserController : Controller
    {
        //
        // GET: /AccountUser/

        GuestBookContext _db = new GuestBookContext();

        protected override void Dispose(bool disposing)
        {
            _db.Dispose();
            base.Dispose(disposing);
        }

        [HttpGet]
        public ActionResult Registration()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Registration(LogOn details)
        {
            ViewBag.validResult = "Null";


                if (ModelState.IsValid)
                {
                    var CreUserFind = _db.accountdetails.Find(details.NEmail);
                    if (CreUserFind != null)
                    {
                        ViewBag.validResult = "Email Taken";
                        ModelState.AddModelError(" ", "The email is already taken");
                    }
                    else
                    {
                        var CreUser = _db.accountdetails.Create();
                        var simplecryp = new SimpleCrypto.PBKDF2();
                        var encrypto = simplecryp.Compute(details.NPassword);

                        CreUser.NEmail = details.NEmail;
                        CreUser.NPassword = encrypto;
                        CreUser.NPasswordSalt = simplecryp.Salt;
                        CreUser.UserId = Convert.ToString(Guid.NewGuid());
                        _db.accountdetails.Add(CreUser);
                        _db.SaveChanges();
                        ViewBag.validResult = "success";
                        ModelState.Clear();
                        ModelState.AddModelError("", "Regitration successfull");

                }

            }
            return View();





模型类



for the model class

namespace GuestBook.Models
{

    public class LogOn
    {
        public string UserId { get; set; }


        [Key]
        [Required(ErrorMessage = "*Enter  password")]
        [Display(Name = "Password")]
        public string NPassword { get; set; }

        [Required(ErrorMessage="*Enter email address")]
        [Display(Name = "Email Address")]
        public string NEmail { get; set; }

        public string NPasswordSalt { get; set; }
    }
}




模型db上下文的




for the model db context

namespace GuestBook.Models
{
    public class GuestBookContext:DbContext
    {
        public GuestBookContext() : base("GuestBook") { }
        public DbSet<guestbookentry> details { get; set; }
        public DbSet<logon> accountdetails { get; set; }
    }
}

推荐答案


这篇关于如何在当前Web请求期间解决未经处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:07