我正在研究ASP.NET MVC4,Web API,我尝试编写密码加密代码 在Register controller中我写了这段代码
namespace PasswordHash.Controllers
{
public class RegisterController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
//POST api/values
public HttpResponseMessage Post(user user)
{
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value");
var db = new passwordhashEntities();
var checkExitUser = (from c in db.users where c.UserName == user.UserName select c).Count();
if (checkExitUser == 0)
{
var newUser = new user()
{
Email = user.Email,
UserName = user.UserName,
Password = PasswordHashHelper.CreateHash(user.Password),
PostCode = user.PostCode,
SlowHash = user.SlowHash
};
db.users.Add(newUser);
db.SaveChanges();
response.Content = new StringContent("Resgister successfully ", Encoding.Unicode);
}
else
response.Content = new StringContent(user.UserName + "is exit", Encoding.Unicode);
return response;
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
}
此行中的运行时错误apear:var checkExitUser =(来自db.users中的c,其中c.UserName == user.UserName select c).Count(); 错误是:类型&#39; System.Data.EntityException&#39;发生在System.Data.Entity.dll中但未在用户代码中处理
我想我需要安装一些工具或程序,但我不知道这个工具是什么?因为我试图应用其他加密教程,并且它也没有与我一起使用同样的错误。