2014-01-15 36 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對象解碼。

相關問題