Azure上的Websecurity.CreateUserAndAccount不起作用

时间:2013-08-07 18:27:52

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 ef-code-first simplemembership

我有一种使用WebSecurity.CreateUserAndAccount(model.UserName, model.Password)注册新用户的方法问题是在UserProfile模型中我添加了GUID密钥。在我的本地机器上,当我调用此方法时,这只会填充一个空的Guid。然而,在azure上,我收到以下错误:

   System.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'Key', table 'Scheduler.dbo.UserProfile'; column does not allow nulls. INSERT fails.

现在,我试图在模型的构造函数中生成一个新的GUID,手动让Set{}生成一个新的GUID,我得到同样的错误。

当我尝试使用CreateUserAndAccount重载时:

 WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Key = Guid.NewGuid() });

我收到以下语法错误(运行时):

 Incorrect syntax near the keyword 'Key'.

我早上花了大部分时间试图解决这个问题,而我却做不到。顺便说一句,上述所有方法仍然会导致空GUID 00000000-0000-0000-0000-000000000000,并且重载会在本地计算机上出现语法错误。

1 个答案:

答案 0 :(得分:0)

“Key”是SQL中的保留字,它应该在括号中使用,如[Key]

由于您无法控制WebSecurity如何生成SQL查询,因此您唯一的选择是将其重命名为UserKey