我正在将url编码数据发布到cshtml文件中。
在发送电子邮件之前,如何解码变量customerEmail
和customerRequest
?
@{
var customerEmail = Request["customerEmail"];
var customerRequest = Request["customerRequest"];
var errorMessage = "";
var debuggingFlag = false;
try {
// Initialize WebMail helper
WebMail.SmtpServer = "your-SMTP-host";
WebMail.SmtpPort = 25;
WebMail.UserName = "your-user-name-here";
WebMail.Password = "your-account-password";
WebMail.From = "your-email-address-here";
// Send email
WebMail.Send(to: customerEmail,
subject: "Dashboard Feedback from - " + customerEmail,
body: customerRequest
);
}
catch (Exception ex ) {
errorMessage = ex.Message;
}
}
答案 0 :(得分:5)
使用System.Web.dll
,您可以解码信息:HttpUtility.UrlDecode
。
示例:
String foo = "foo%40bar.com";
String bar = HttpUtility.UrlDecode(foo);
// bar = "foo@bar.com"
但我要提一下,传入的信息应该已经通过Request
对象解码了。
答案 1 :(得分:3)
你没有。
Request
对象已为您解码所有内容。