Razor .NET文件中的URL解码(cshtml)

时间:2014-01-15 16:38:29

标签: c# .net razor

我正在将url编码数据发布到cshtml文件中。 在发送电子邮件之前,如何解码变量customerEmailcustomerRequest

@{
    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;
    }
}

2 个答案:

答案 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对象已为您解码所有内容。