Cannot find directory when sending email after registration RRS feed

  • Question

  • User-1352156089 posted

    Dear All,

    I have implemented the below code to send users that have just registered a welcome message along with a confirmation code to verify their accounts. I am using a template which is located in the following path: ~/account_templates/registration.html

    The code is the following:

    Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
            Dim FirstName As String = registerfirstnametxt.Text
            Dim LastName As String = registerlastnametxt.Text
            Dim Newsletter As Boolean = If(registernewslettercheckbox.Checked, True, False)
            Dim userName As String = registerEmailtxt.Text
            Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
            Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()
            Dim user = New ApplicationUser() With {.UserName = userName, .Email = userName, .FirstName = FirstName, .LastName = LastName, .Newsletter = Newsletter}
            Dim result = manager.Create(user, registerPasswordtxt.Text)
     If result.Succeeded Then
                Dim code = manager.GenerateEmailConfirmationToken(user.Id)
                Dim callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id)
                Dim mailbody As String
                mailbody = System.IO.File.ReadAllText("~/account_templates/registration.html")
                mailbody = mailbody.Replace("##NAME##", FirstName)
                Dim url As String = callbackUrl
                mailbody = mailbody.Replace("##CONFIRM##", url)
                manager.SendEmail(user.Id, "Confirm your account", mailbody)
                If user.EmailConfirmed Then
                    signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=False)
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
                    registerconfirmation.Visible = True
                    registerinnerpanel.Visible = False
                    registererrorpanel.Visible = False
                End If
                'ErrorMessage.Text = result.Errors.FirstOrDefault()
                resistererrormessagetxt.Text = "This email address already has an account. Please <a href=""login"">sign in</a>"
                registererrorpanel.Visible = True
            End If
        End Sub

    When I debug my application, the error on subject is reported for this line of code:

    mailbody = System.IO.File.ReadAllText("~/account_templates/registration.html")

    Any idea about why this is happening? 

    I doubled checked the directory and it is correct without typo.


    Wednesday, April 15, 2015 2:53 PM


  • User-1352156089 posted

    It was actually the wrong path. Sorry

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 16, 2015 12:15 PM