RE: How To Add User's GUID To An Account Verification E-mail



Finally, determined the cause of the error. The DB had two application IDs
while I specified the applicationName in the membership provider, I needed to
specify the applicationName that I was looking for users in.



"Jonathan Gill" wrote:

Hi everyone,
So I have a problem that is more difficult that it might seem at first
glance. created. Any help/a clever "duh" answer would be great as we've
spent more than 8 hours trying to get this working.

Please see the following thread for the full details:

"How To Add User's GUID To An Account Verification E-mail - E-mail Working,
Error In Retreiving GUID"

http://forums.asp.net/p/1172523

----
am receiving an error when I try to retrieve a newly (and
successfully...checked the DB) registered users GUID to include in an account
verification e-mail. I am using the e-mail that is sent by the membership
provider, however I am adding an extra step for the user to verify their
account. The e-mail works fine as long as I don't try and use the user's
GUID. The verification of a user's account step uses a newly defined
placeholder (<% Username %> and <% Password %> are supported by default in
asp.net membership) in the .txt file that is the basis for the e-mail. I can
get the placeholder to replace fine in the e-mail, however I get an error
when I try to include the user's GUID in the e-mail.

Here are examples:
http://www.pcw.co.uk/personal-computer-world/features/2153686/membership-rules?page=3,
http://dotnetjunkies.com/WebLog/saravana/archive/2006/04/30/137645.aspx

Any help with fixing the error is appreciated. Thanks!



Error

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_rih02pg9"
StackTrace:
at signup.CreateUserWizard1_SendingMail(Object sender,
MailMessageEventArgs e) in C:\Documents and Settings\Owner\My
Documents\Visual Studio 2005\WebSites\Test\Signup.aspx.vb:line 81
at
System.Web.UI.WebControls.CreateUserWizard.OnSendingMail(MailMessageEventArgs
e)
at System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email,
String userName, String password, MailDefinition mailDefinition, String
defaultSubject, String defaultBody, OnSendingMailDelegate
onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate,
Control owner)


Protected Sub CreateUserWizard1_SendingMail(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles
CreateUserWizard1.SendingMail
Dim tempMem As MembershipUser =
Membership.GetUser(CreateUserWizard1.UserName)

'Replace placeholder for the verification URL
e.Message.Body = Replace(e.Message.Body, "<% VerifyURL %>",
"http://www.test.com/VerifyAccount.aspx?key="; &
tempMem.ProviderUserKey.ToString) ' Error occurs on this line
'Line below will work and replace the placeholder in the e-mail file
'e.Message.Body = e.Message.Body.Replace("<% VerifyURL %>",
"http://www.test.com/VerifyAccount.aspx?key=123)

End Sub Protected Sub CreateUserWizard1_SendingMail(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles
CreateUserWizard1.SendingMail
Dim tempMem As MembershipUser =
Membership.GetUser(CreateUserWizard1.UserName.ToString)
MsgBox(tempMem.ProviderUserKey.ToString) ' Will return error here

'Replace placeholder for the verification URL
e.Message.Body = Replace(e.Message.Body, "<% VerifyURL %>",
"http://www.test.com/VerifyAccount.aspx?key="; &
tempMem.ProviderUserKey.ToString) ' Error occurs on this line
'Line below will work and replace the placeholder in the e-mail file

'e.Message.Body = e.Message.Body.Replace("<% VerifyURL %>",
"http://www.test.com/VerifyAccount.aspx?key=123)
End Sub
.



Relevant Pages

  • Re: How to find "in" in the documentation
    ... if string in bigstring: ... The operators in and not in test for collection membership. ... collection membership test has traditionally been bound to ... lower integer indices do not raise IndexError exception. ...
    (comp.lang.python)
  • Re: How to find "in" in the documentation
    ... if string in bigstring: ... The operators in and not in test for collection membership. ... collection membership test has traditionally been bound to ... lower integer indices do not raise IndexError exception. ...
    (comp.lang.python)
  • Re: Log on script error
    ... There should be no reason to specify a particular DC in the binding string, ... make sure the script works in all 3 possible ... strGroups = LCase ... ways to check group membership. ...
    (microsoft.public.windows.server.scripting)
  • Re: Roles in membership database
    ... Membership classes - thanks for your help. ... if (!Roles.IsUserInRole (userName, roleName)) ... Roles.AddUsersToRole(new string[] {userName}, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Characters contain themselves?
    ... the village barber shaves all and only those who don't shave ... contains itself but that string X can contain another string Y (i.e. ... The operators in and not in test for set membership. ...
    (comp.lang.python)