简体   繁体   中英

Can we place JavaScript Code along c# in .NetCore WebApi

I have a method in my asp.net Core web Api that has for role sending Emails, using SmtpClient . the Body of the message is this html string:

  @"<html>
         <head>
              <style>
                   #modalHeader{
                        background-color:#6495ED;
                        color:white;
                        text-align: center;
                        height:80px;
                       }  
                        .example_b {
                                      color: #fff !important;
                                      text-transform: uppercase;
                                      text-decoration: none;
                                      background: #60a3bc;
                                      padding: 20px;
                                      border-radius: 50px;
                                      display: inline-block;
                                      border: none;
                                      transition: all 0.4s ease 0s;
                                     }
                                    .example_b:hover {
                                            text-shadow: 0px 0px 6px rgba(255, 255, 255, 1);
                                            -webkit-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
                                            -moz-box-shadow: 0px 5px 40px -10px rgba(0,0,0,0.57);
                                            transition: all 0.4s ease 0s;
                                            }
                                </style>
                            </head>
                      <body>
                        <p>Bonjour,<br> 
                            Afin d’authentifier votre connexion sur le système de prise de rendez-vous à distance de la " + Structure + @" Nous vous invitons à  confirmer votre mail en cliquant sur ce lien 
                         </p>
                    <div style='border:1px solid black'>
                          //<div id='modalHeader'>Confirmation d'Email</div>
                            //<br>
                                //<br>
                            <div id='modalBody'>
                              <div class='button_cont' align='center'>
                                <a class='example_b' href='" + url + "' target='_blank' rel='nofollow noopener'>Confirmer Votre Email</a>" +
                                "</div> </div> <br/> </div> </body> </html>";

as you see im using a href to trigger a call to another method in service, the problem with that is that it opens to me a blank page each time i click the button, so the solution would be to add an event instead to the button using javascript.

My question is how can i add Js to c# code in asp.net core 2.1? is adding just script tag inside the html tag would make the work of letting JS doing the work?

You can't execute javascript inside an email. This used to be possible in the 90's and early 2000's, but it is no longer possible.

If you inspect the element in the email are you sure you see the correct url? If yes maybe it would be worth giving a try to inspect an href link in one email. I checked at the moment and I saw something like that: 在此处输入图像描述 It could be worth the try...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM