locked
Coding breaks and % signs RRS feed

  • Question

  • User-1793215261 posted

    Hello

    In Microsoft's Identity Template (new users), the Register.aspx.vb file looks like this:

    Partial Public Class Register
        Inherits Page
        Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
            Dim userName As String = Email.Text
            Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
            Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()
            Dim user = New ApplicationUser() With {.UserName = userName, .Email = userName}
            Dim result = manager.Create(user, Password.Text)
            If result.Succeeded Then
                
                Dim code = manager.GenerateEmailConfirmationToken(user.Id)
                Dim callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request)
                manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=""" & callbackUrl & """>here</a>.")
    
                signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=False)
                IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
            Else
                ErrorMessage.Text = result.Errors.FirstOrDefault()
            End If
        End Sub

    Under IdentityHelper, I have added this line to inform the user to click on a link in his email to confirm his email:

     Response.Redirect("~/success_test.aspx") 

     and the redirection works. However, if I add to the line "Please confirm your account..." so that it reads:

     manager.SendEmail(user.Id, "Confirm your account", "Dear <% Email %><br><br>Please confirm your account by clicking <a href=""" & callbackUrl & """>here</a>.")<br><br>Please find your account details below:<br><br>Email: <% Email %><br>Password: <% Password %>

    VS 2017 does not like my line breaks or percentage symbols. How should I be coding them, please?

    Basically, I would like the email the user receives to look something like:
      
       Dear John@site.com
      
       Your account has been created.
      
       Please confirm your email by clicking here (link).
      
       Your account details are as follows:
      
       Email: <% Email %>
       Password: <% Password %>

      Regards

      Whoever.

    Or maybe it would be easier to send the user a text file instead of using many inverted commas, line breaks, percentage signs, etc?

    Thanks for any suggestions. 

    Wednesday, May 1, 2019 10:08 AM

All replies

  • User475983607 posted

    Use standard string concatenation or string interpolation as shown below to build the string.

    manager.SendEmail(user.Id, $"Confirm your account", "Dear {Email}<br><br>Please confirm your account by clicking <a href=""" & callbackUrl & """>here</a>.")<br><br>Please find your account details below:<br><br>Email: <% Email %><br>Password: {Password}

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated

    The code sample above assumes Email and Password are variables.

    Wednesday, May 1, 2019 1:47 PM
  • User-1793215261 posted

    Many thanks again, mgebhard

    I am not at my usual PC at the moment so will try the code later and post back.

    Thanks, too, for the link which I have saved.

    Wednesday, May 1, 2019 2:48 PM