ASP.net UserCreate 向导中的奇怪错误
我有一个奇怪的错误。在用户创建过程中,如果系统中已存在用户名,我会对其进行一些检查,如果现有帐户尚未激活,则允许用户再次注册。我收到一条错误消息:
[NullReferenceException: Object reference not set to an instance of an object.]
LAUNCHOnline.en.ca.CreateUser.wCreateUser_Error(Object sender, CreateUserErrorEventArgs e) in C:\Projects\LAUNCH\LAUNCH-Online\LAUNCHOnline\en\ca\CreateUser.aspx.cs:194
我的代码:(var vUser 是导致错误的行)
protected void wCreateUser_Error(object sender, CreateUserErrorEventArgs e)
{
// TODO: more verbose error messages.
if (e.CreateUserError == MembershipCreateStatus.DuplicateEmail)
{
// WORK IN PROGRESS
// If the user is not activated yet, update the existing user info with the new info
// as it might be a feedback user. Else, give an error.
// Get the user from the database.
var vUser = (from u in this.dcLAUNCHOnline.aspnet_Users
where u.UserName.Equals(this.wCreateUser.UserName)
select u).Single();
注意:用户的用户名只是他们的电子邮件。我手动检查过,收到此错误的人确实已经在数据库中拥有帐户,但仍然收到此错误。用户名的大小写并没有导致问题,因为我尝试了临时帐户的不同情况,并且效果很好。
感谢任何帮助 - 谢谢!
I'm having a weird error. During user creation, if a username already exists in the system, I do a few checks on it and allow the user to sign up again if the existing account is not activated yet. I'm getting an error that says:
[NullReferenceException: Object reference not set to an instance of an object.]
LAUNCHOnline.en.ca.CreateUser.wCreateUser_Error(Object sender, CreateUserErrorEventArgs e) in C:\Projects\LAUNCH\LAUNCH-Online\LAUNCHOnline\en\ca\CreateUser.aspx.cs:194
My Code: (var vUser is the line causing the error)
protected void wCreateUser_Error(object sender, CreateUserErrorEventArgs e)
{
// TODO: more verbose error messages.
if (e.CreateUserError == MembershipCreateStatus.DuplicateEmail)
{
// WORK IN PROGRESS
// If the user is not activated yet, update the existing user info with the new info
// as it might be a feedback user. Else, give an error.
// Get the user from the database.
var vUser = (from u in this.dcLAUNCHOnline.aspnet_Users
where u.UserName.Equals(this.wCreateUser.UserName)
select u).Single();
Note: The user's username is just their email. I manually checked, and people who are getting this error do have an account in the database already, but still get this error. The case of the username didn't cause the problem, as I tried different cases with temp accounts and it worked fine.
Any Help appreciated - thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果从该行抛出 NullReferenceException 异常:
问题必须是以下实例之一(或缺少它):
dcLAUNCHOnline.aspnet_Users
this.wCreateUser
或没有结果
from u in this.dcLAUNCHOnline.aspnet_Users where u.UserName.Equals(this.wCreateUser.UserName)
我建议你调试一下,找出哪一个或多个是
null
。If the NullReferenceException exception is thrown from this line:
The problem has to be one of the following instances (or the lack of it):
dcLAUNCHOnline.aspnet_Users
this.wCreateUser
OR no result from
from u in this.dcLAUNCHOnline.aspnet_Users where u.UserName.Equals(this.wCreateUser.UserName)
I suggest you debug through to find out which one or more is/are
null
.