Search code examples
c#asp-classichyperlinkoutlookhtml-encode

Outlook changes & to &


I habe an ASP website, and I want to send an EMail using a Template. In the template i have two placeholders inside an <a href=""> (%CODE% and %EMAIL%) they are supposed to be query strings

it looks kinda like this

<a href="http://www.foo.com?qs1=example&Code=%CODE%&Email=%EMAIL%" />

I use the .Replacement() Method to replace the two fields.

The Problem is that after receiving the email, the & characters are replaced by &amp; and the the query string becomes invalid.

I don't know if this is a Outlook Problem (2013) or if it can be fixed within the code.

Thanks


Solution

  • Ampersands aren't valid in this context.

    If you "encode" them yourself before Outlook can.. it will switch it back to normal for you:

    <a href="http://www.foo.com?qs1=example&amp;Code=%CODE%&amp;Email=%EMAIL%" />
    

    So you use amp;, and Outlook will fix it. Browsers do the same thing.

    Even if it doesn't look like it in the page source.. if you click the link the amp; will be replaced with a normal ampersand.