1

I want to call router with multiple parameters using C#.Here is i am making url

 var _email = UtilityConverter.Encrypt(Email);
            var _userId = UtilityConverter.Encrypt(Convert.ToString(UserId));

            // this.router.navigate(['search', { term: term}]);

            var _subject = "Email Verification";
            StringBuilder sb = new StringBuilder();
            sb.Append("<html>");
            sb.Append("<body>");
            sb.Append("<p>Dear ,</p>");
            sb.Append("<p>Please click the below link to verify your email.</p><br>");
            sb.Append("<a href='http://localhost:4200/Emailverification/" + _email + "/" + _userId + "'>click here</a>");
            sb.Append("<p>Sincerely,<br>-Offey</br></p>");
            sb.Append("</body>");
            sb.Append("</html>");
            return MailUtilityHelper.SendMail(Email, _subject, sb.ToString());

My Email and userid is encrypted which cause the issue.

here is my router with multiple parameter

 {path:'Emailverification/:email/:userid', component:EmailVerficationComponent,canActivate : [AuthguardComponent]},

any help will be highly appreciated. gives me following error in console.

enter image description here

Shamshad Jamal
  • 19
  • 3
  • 17

2 Answers2

1

You are passing only one parameter to you'r router which is Emailverification/something

in you'r case you have to fill both the parameters to the url. If you want to make route parameters nullable you should declare another route with one parameter and another one with no parameter which should be

 {path:'Emailverification', component:EmailVerficationComponent,canActivate : [AuthguardComponent]},
 {path:'Emailverification/:userid', component:EmailVerficationComponent,canActivate : [AuthguardComponent]},
 {path:'Emailverification/:email', component:EmailVerficationComponent,canActivate : [AuthguardComponent]},

or you can catch error in you'r component:EmailVerficationComponent component.

Arash
  • 1,692
  • 5
  • 21
  • 36
1

You should encrypt your email and userid by using some other encryption method. I will provide you encryption and decryption method without special characters. Which will solve your problem.

       public static string Encrypt(string stringvalue, System.Text.Encoding encoding)
    {
        Byte[] stringBytes = encoding.GetBytes(stringvalue);
        StringBuilder sbBytes = new StringBuilder(stringBytes.Length * 2);
        foreach (byte b in stringBytes)
        {
            sbBytes.AppendFormat("{0:X2}", b);
        }
        return sbBytes.ToString();
    }
    public static string Decrypt(string hexvalue, System.Text.Encoding encoding)
    {
        int CharsLength = hexvalue.Length;
        byte[] bytesarray = new byte[CharsLength / 2];
        for (int i = 0; i < CharsLength; i += 2)
        {
            bytesarray[i / 2] = Convert.ToByte(hexvalue.Substring(i, 2), 16);
        }
        return encoding.GetString(bytesarray);
    }

Hope this helps you though it is not optimize solution but it may help you go through your problem.

Kamran Khan
  • 1,042
  • 10
  • 21