c#
  • asp.net
  • email
  • smtp
  • 2017-06-01 158 views 1 likes 
    1

    早上好,在电子邮件中发送链接

    我目前正试图在用户填写表单后发送电子邮件。该电子邮件包含指向激活页面的链接。我对生成的链接代码如下:

    mailMessage.Body = "<h1>Please click the link below to activate your account</h1><br /><a href = '" + HttpContext.Current.Request.Url.AbsoluteUri.Replace("Activation.aspx", "Activation.aspx?userId=" + userId) + "'>Click here to activate your account.</a>"; 
    

    然而,当发送的电子邮件显示的网址:

    http://localhost:52621/RegisterUser.aspx 
    

    我在做什么错?如生成链接的代码所示,我试图通过Activation.aspx的名称访问页面,该页面没有发生。任何建议都会很棒。提前致谢。

    +0

    请告诉我绝对URI的内容? –

    +0

    你很明显从RegisterUser.aspx页面获取Uri。此外,您可能想要将“?userId = ...”部分追加到AbsoluteUri中,而不是替换其中的一部分,因为Uri(在您检索它之后)可能以“Activation.aspx”结尾。 –

    +0

    https://stackoverflow.com/questions/10719722/asp-net-app-to-send-an-mail-with-a-hyperlink –

    回答

    0

    您正在运行本地开发服务器端口52621,这就是为什么你会得到上述URL。

    当您发布项目会显得不同,在一些领域probally捉迷藏一样

    https://www.example.com/RegisterUser.aspx 
    

    如果你想拥有从公布的状态的一个解决方案是链接到它手工编码:

    mailMessage.Body = "<h1>Please click the link below to activate your account</h1><br /><a href='https://www.example.com/Activation.aspx?userId=" + userId + "'>Click here to activate your account.</a>"; 
    

    虽然我不喜欢那个。

    如果你有你的项目将被发布到你可以根据当前构建配置自己的域名写入web.config文件喜欢这里描述的多种环境:

    Using different Web.config in development and production environment

    +0

    谢谢你的回答。最后,我采用了不同的验证方法。无论如何,我已经接受了这个答案,因为你给了我几件事情来思考。谢谢 –

    +1

    很高兴我能帮忙,谢谢! – Cossintan

    相关问题