I wanna send validation email using sqlserver database email sender mechanism.
I have created an e trigger that sends email to users.
ALTER TRIGGER [dbo].[SendActivationMail]
ON [dbo].[aspnet_Membership]
AFTER INSERT
AS
BEGIN
DECLARE @mail NVARCHAR(50)
DECLARE @userid NVARCHAR(150)
DECLARE @mailBody NVARCHAR(500)
DECLARE @username NVARCHAR(50)
set @userid = (select UserId from INSERTED)
set @mail = (select Email From INSERTED)
set @username =(select Username From MyMembersTable.dbo.aspnet_Users
where UserId = @userid)
This is C# code, not stored proc code. In the first post you generated the email with Stored Proc. Now you generate with C#? Please be consistent in your problem!
This is C# code, not stored proc code. In the first post you generated the email with Stored Proc. Now you generate with C#? Please be consistent in your problem!
I am consistent about question. I am asking, I sended the mail from trigger. I get the userid that created in inserted table while inserting data. But later the mail is verified in asp.net code with produced userid by database. But the userid is different
in inserted table and aspnet_Membership table.
firtinalim
Member
40 Points
67 Posts
Authentication email userid problem
Jun 12, 2012 01:53 PM|LINK
hi,
I wanna send validation email using sqlserver database email sender mechanism.
I have created an e trigger that sends email to users.
ALTER TRIGGER [dbo].[SendActivationMail]
ON [dbo].[aspnet_Membership]
AFTER INSERT
AS
BEGIN
DECLARE @mail NVARCHAR(50)
DECLARE @userid NVARCHAR(150)
DECLARE @mailBody NVARCHAR(500)
DECLARE @username NVARCHAR(50)
set @userid = (select UserId from INSERTED)
set @mail = (select Email From INSERTED)
set @username =(select Username From MyMembersTable.dbo.aspnet_Users
where UserId = @userid)
'http://www.doamin.com/Account/Verify?Id='+@userid
send email.....
This sends email. but I noticed this, the INSERTED userid value is shorter one charecter from the afret inserted.
For exampler the email link is following
http://www.mydomain.com/Account/Verify?Id=934c1165-c0a0-4fcd-8a31-7f2eebfbd87
the userid is 934c1165-c0a0-4fcd-8a31-7f2eebfbd87 and when I open the table and copy the user id is
934c1165-c0a0-4fcd-8a31-7f2eebfbd87c
this is added one charecter the end of the userid INSERTED table.
so I cannot verify user.
aabruzzese
Contributor
2806 Points
759 Posts
Re: Authentication email userid problem
Jun 12, 2012 02:23 PM|LINK
Did you do a few basic select statements to see what is returned in the variable?
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Authentication email userid problem
Jun 12, 2012 02:44 PM|LINK
how do you generate this link?
firtinalim
Member
40 Points
67 Posts
Re: Authentication email userid problem
Jun 13, 2012 07:27 PM|LINK
MembershipUser user = Membership.GetUser(username); string confirmationGuid = user.ProviderUserKey.ToString(); string verifyUrl = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/Verify?Id=" + confirmationGuid;ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Authentication email userid problem
Jun 14, 2012 02:51 AM|LINK
This is C# code, not stored proc code. In the first post you generated the email with Stored Proc. Now you generate with C#? Please be consistent in your problem!
firtinalim
Member
40 Points
67 Posts
Re: Authentication email userid problem
Jun 14, 2012 06:02 AM|LINK
I am consistent about question. I am asking, I sended the mail from trigger. I get the userid that created in inserted table while inserting data. But later the mail is verified in asp.net code with produced userid by database. But the userid is different in inserted table and aspnet_Membership table.
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Authentication email userid problem
Jun 14, 2012 07:33 AM|LINK
How do you insert into "inserted table"? What's the definition of "inserted table"?
And I understand problem is not on sending email, but on tables....
firtinalim
Member
40 Points
67 Posts
Re: Authentication email userid problem
Jun 14, 2012 10:36 AM|LINK
The definition of "inserted table" is in trigger. After inserted, dleted, updated....
set @userid = (select UserId from INSERTED)
when a new user inserted the aspnet_Memebership table u can select the data from inserted like this.
set @userid = (select UserId from INSERTED)
so I can get the produced new userId , when a new user created.
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: Authentication email userid problem
Jun 14, 2012 11:01 AM|LINK
Ok. Show the definition of mailbody, where you put the link.