我一直在开发一个网站,该网站必须发送一封包含 URL 的电子邮件,但是,该 URL 打印时带有多余的“;”在里面。 例如:
In order for us to continue with your request, please click here to confirm your email address or paste the following link in to your browser: http://localhost/Account/ConfirmEmail?userId=605fa142&code;=7fBi8oRavW6C
上述 URL 的第二个实例不应包含“;”在“代码”参数之后。您会注意到 <a href>here</a>
中的 URL没有额外的撇号。
我已经用 IE 和 Chrome 尝试过,并得到相同的结果。我怀疑浏览器放入了撇号,但我不知道为什么。
电子邮件文本是从资源文件中提取的:
<p>Dear {0}<p></BR><p>Thank you for signing up to access the Extranet with the email address {1}.</p><p>In order for us to continue with your request, please click <a href="{2}">here</a> to confirm your email address or paste the following link in to your browser:</BR><a href="{2}">{2}</a>
并使用 string.format()
填充详细信息:
string.Format(ConfirmEmailBody, firstName, email, callbackUrl)
过去几个小时我一直在努力解决这个问题,我唯一能想到的是序列 &code=
具有某种意义。其他人以前见过这个吗?
编辑 1
callbackUrl 是使用以下代码生成的:
var callbackUrl = Url.Action("ConfirmEmail", "Account",
new { userId = userID, code = code }, protocol: Request.Url.Scheme);
创建callbackUrl后,我在VS中放置了一个断点,并且生成的URL不包含撇号。
编辑2
看来“代码”没有任何意义。我更改了 URL 参数,浏览器为每个参数打印带有多余撇号的字符串:
localhost/Account/ConfirmEmail?userId=80216107-1d0e-432c-88cc-69f18be2111e&foo;=wibble&bar;=wobble
最佳答案
似乎有东西试图将 &code
解释为 html 转义序列,并添加分号来完成该序列。
在将字符串添加到原始 html 之前,您必须对其进行转义,将 &
更改为 &
。
关于c# - 字符串中的 URL 被撇号损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32582189/