2014-01-15 31 views
1

我将url编码数据发布到cshtml文件。 在我发送电子邮件之前,如何解码变量customerEmailcustomerRequestRazor .NET文件中的URL解码(cshtml)

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

“解码”?他们是“foo%40bar.com”吗? –

+0

我不确定用cshtml发送电子邮件是个好主意,它是视图,它与发送电子邮件无关。 –

+0

@DanielGrankin,这不是MVC,我想他使用的是WebMatrix。 –

回答

2

你不知道。

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

5

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

实施例:

String foo = "foo%40bar.com"; 
String bar = HttpUtility.UrlDecode(foo); 
// bar = "[email protected]" 

但是我应该提到,输入信息应已通过Request对象解码。

相关问题