0

I need to URL encode an email address. If I do this (without URL encode), it works:

<!DOCTYPE html>
<head>
    <title>Test</title>
</head>
<body>
    <a href="https://www.example.com/reset-password?e=%7bEMAILADDRESS%7d">
</body>
</html>

The email address is printed raw, not URL-encoded.

What I'd really like to do is the following, but HttpUtility.UrlEncode() doesn't execute:

<!DOCTYPE html>
<head>
    <title>Test</title>
</head>
<body>
    <a href="https://www.example.com/reset-password?e=HttpUtility.UrlEncode("%7bEMAILADDRESS%7d")">
</body>
</html>

Any suggestions on how to execute HttpUtility.UrlEncode() for usage in the above manner? Thanks for any help.

GTS Joe
  • 3,612
  • 12
  • 52
  • 94
  • For more information on inline expressions in asp.net.... https://learn.microsoft.com/en-us/troubleshoot/aspnet/inline-expressions – quaabaam Sep 09 '20 at 16:32

1 Answers1

3

You need to use <%= %>

like:

<a href="https://portal.nchinc.com/reset-password?e= 
 <%=HttpUtility.UrlEncode("%7bEMAILADDRESS%7d") %>"/>

The <%= ... %> is used when you need to display an expression.

Dalorzo
  • 19,834
  • 7
  • 55
  • 102