my problem it is not in emailMessage, my problem in userid see full erorr:
Server Error in '/' Application.
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 13: // Lets get the user's id
Line 14:
Line 15: Guid userId = (Guid)Membership.GetUser(userName).ProviderUserKey;
Line 16:
Line 17: // Now lets create an email message
Source File: d:\Google Drive\1-ASP.NET\1-Web Forms\4.5\0-WebSite\Under Constraction\www.aindapress.com\Login.aspx.cs Line: 15
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
Login.CreateUserWizard1_CreatedUser(Object sender, EventArgs e) in d:\Google Drive\1-ASP.NET\1-Web Forms\4.5\0-WebSite\Under Constraction\www.aindapress.com\Login.aspx.cs:15
System.Web.UI.WebControls.CreateUserWizard.OnCreatedUser(EventArgs e) +111
System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +354
System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +102
System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +418
System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +161
System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +19
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1502: The best overloaded method match for 'System.Guid.Guid(byte[])' has some invalid arguments
Source Error:
Line 13: // Lets get the user's id
Line 14:
Line 15: Guid userId = new Guid(Membership.GetUser(userName).ProviderUserKey);
Line 16:
Line 17: // Now lets create an email message
Source File: d:\Google Drive\1-ASP.NET\1-Web Forms\4.5\0-WebSite\Under Constraction\www.aindapress.com\Login.aspx.cs Line: 15
peshangm
Member
73 Points
137 Posts
Specified cast is not valid.
Feb 24, 2013 10:22 AM|LINK
dear all
when user want to register account the display this error :
Specified cast is not valid.
please what it the solution
<div></div><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Login</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Login ID="Login1" runat="server"> </asp:Login> <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" oncreateduser="CreateUserWizard1_CreatedUser" DisableCreatedUser="true"> <WizardSteps> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" /> <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server" /> </WizardSteps> </asp:CreateUserWizard> </div> </form> </body> </html> using System; using System.Web.Security; using System.Text; using System.Net.Mail; public partial class Login : System.Web.UI.Page { protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { string userName = CreateUserWizard1.UserName; string emailAddress = CreateUserWizard1.Email; // Lets get the user's id Guid userId = (Guid)Membership.GetUser(userName).ProviderUserKey; // Now lets create an email message StringBuilder emailMessage = new StringBuilder(); emailMessage.Append("Thank you for creating an account with YourDomain.com"); emailMessage.Append("<br />"); emailMessage.Append("Please click the below link to activate your account <br />"); emailMessage.Append(string.Format("<a href='http://www.YourDomain.com/ActivateUser.aspx?userName{0}&Id={1}'>Activate {0} </a>", userName, userId.ToString())); MailMessage email = new MailMessage(); email.From = new MailAddress("noReply@YourDomain.com"); email.To.Add(new MailAddress(emailAddress)); email.Subject = "Please activate your account with YourDomain"; email.Body = emailMessage.ToString(); email.IsBodyHtml = true; // Send the email SmtpClient client = new SmtpClient(); client.Send(email); // Redirecto to What ever page Response.Redirect("Default.aspx", true); } }Suly Web For It Solution.
dotnetsoluti...
Member
76 Points
14 Posts
Re: Specified cast is not valid.
Feb 24, 2013 12:42 PM|LINK
try this
emailMessage.Append("Please click the below link to activate your account"+"<br />");countycowpok...
Participant
1411 Points
340 Posts
Re: Specified cast is not valid.
Feb 24, 2013 02:42 PM|LINK
Check you userid cast from providerkey and also may need to use / on your single quotes.
/'http://www.website.com/' inside your double quotes for url
peshangm
Member
73 Points
137 Posts
Re: Specified cast is not valid.
Feb 24, 2013 07:05 PM|LINK
thanks for your replay
my problem it is not in emailMessage, my problem in userid see full erorr:
Suly Web For It Solution.
peshangm
Member
73 Points
137 Posts
Re: Specified cast is not valid.
Feb 24, 2013 07:46 PM|LINK
this is my defaultProvider
<membership defaultProvider="AccessMembershipProvider" userIsOnlineTimeWindow="15"> <providers> <clear/> <add name="AccessMembershipProvider" type="Samples.AccessProviders.AccessMembershipProvider, SampleAccessProviders" connectionStringName="AccessFileName" enablePasswordRetrieval="true" enablePasswordReset="true" requiresUniqueEmail="false" requiresQuestionAndAnswer="false" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" applicationName="SampleSite" hashAlgorithmType="SHA1" passwordFormat="Clear" /> </providers> </membership>Suly Web For It Solution.
dotNetViper
Member
676 Points
151 Posts
Re: Specified cast is not valid.
Feb 24, 2013 08:04 PM|LINK
try this
Viper
My Blog | Software Pulse
(Please Mark as Answer if you find the reply useful)
The only dumb question is the unasked question.
peshangm
Member
73 Points
137 Posts
Re: Specified cast is not valid.
Feb 24, 2013 08:13 PM|LINK
thank i try it but also have erorr overlod
Suly Web For It Solution.
peshangm
Member
73 Points
137 Posts
Re: Specified cast is not valid.
Feb 24, 2013 08:36 PM|LINK
i thisk the problem in Guid datatype, becouse i use ms accsess
Suly Web For It Solution.
ninianne98
Contributor
3896 Points
648 Posts
Re: Specified cast is not valid.
Feb 25, 2013 01:06 AM|LINK
the syntax I use to get newly registered use's GUIDs is
The SecurityData entity is some group name constants.
protected void createWizard_CreatedUser(object sender, EventArgs e) { var pb = ProfileBase.Create(createWizard.UserName, false); Roles.AddUserToRole(createWizard.UserName, SecurityData.CMSGroup_Users); try { MembershipUser usr = Membership.GetUser(createWizard.UserName); Guid userID = new Guid(usr.ProviderUserKey.ToString()); Response.Redirect("./User.aspx?id=" + userID.ToString()); } catch (Exception ex) { } }Mark as Answer if this response was helpful.
peshangm
Member
73 Points
137 Posts
Re: Specified cast is not valid.
Feb 25, 2013 05:40 PM|LINK
i try it but it is not solved, For your information my dada base it is MS access
Suly Web For It Solution.