繁体   English   中英

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

[英]URL decode in Razor .NET file (cshtml)

我正在将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;
    }
}

使用System.Web.dll可以解码信息: HttpUtility.UrlDecode

例:

String foo = "foo%40bar.com";
String bar = HttpUtility.UrlDecode(foo);
// bar = "foo@bar.com"

但是我应该提到,传入的信息应该已经通过Request对象进行了解码。

你不知道

Request对象已经为您解码了所有内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM