通过C#中的查询字符串传递电子邮件地址

use*_*554 3 c# url

我想发送一个URL给一个人。该URL需要包含一个电子邮件地址。基本上,我想要看起来像这样的东西:

http://www.mydomain.com/page.aspx?e=emailAddress@network.com
Run Code Online (Sandbox Code Playgroud)

据我了解,我无法直接通过URL传递电子邮件地址。相反,我需要先对其进行编码。我的理解正确吗?如果是这样,如何使用C#对其进行编码?我看到了各种各样的编码选项,但是我不确定该使用什么。

谢谢!

Chr*_*rle 5

如果使用C#进行操作,请使用HttpServerUtility.UrlEncode将某些内容编码为url。

从文章:

String MyURL;
MyURL = "http://www.contoso.com/articles.aspx?title=" + Server.UrlEncode("ASP.NET Examples");
Run Code Online (Sandbox Code Playgroud)

或您的情况:

String MyURL = "http://www.mydomain.com/page.aspx?e=" + Server.UrlEncode("emailAddress@network.com");
Run Code Online (Sandbox Code Playgroud)


Jon*_*ood 4

是的,使用诸如HttpUtility.UrlEncode().

但是,您所显示的内容在 URL 查询参数中传递电子邮件。不确定向某人发送 URL 是什么意思。