我正在将 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;
}
}
最佳答案
使用 System.Web.dll
您可以解码信息:HttpUtility.UrlDecode
.
例子:
String foo = "foo%40bar.com";
String bar = HttpUtility.UrlDecode(foo);
// bar = "foo@bar.com"
但我要提一下,传入的信息应该已经通过 Request
对象进行了解码。
关于c# - Razor .NET 文件 (cshtml) 中的 URL 解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21143110/