ASP.net UserCreate 向导中的奇怪错误

发布于 2024-08-09 17:23:36 字数 1181 浏览 1 评论 0原文

我有一个奇怪的错误。在用户创建过程中,如果系统中已存在用户名,我会对其进行一些检查,如果现有帐户尚未激活,则允许用户再次注册。我收到一条错误消息:

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┊风居住的梦幻卍 2024-08-16 17:23:36

如果从该行抛出 NullReferenceException 异常:

var vUser = (from u in this.dcLAUNCHOnline.aspnet_Users
                         where u.UserName.Equals(this.wCreateUser.UserName)
                         select u).Single();

问题必须是以下实例之一(或缺少它):
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:

var vUser = (from u in this.dcLAUNCHOnline.aspnet_Users
                         where u.UserName.Equals(this.wCreateUser.UserName)
                         select u).Single();

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文