2012-06-26 82 views
2

我送我的web應用程序的用戶郵件的鏈接(用於確認用戶註冊),如下面的Base64編碼參數:問題在查詢字符串

<a target="_blank" href="http://localhost:2817/ConfirmRegistration?confirm=Y0tcmGepe7wjH7A1CT1IaA=="> 
http://localhost:2817/ConfirmRegistration?confirm=Y0tcmGepe7wjH7A1CT1IaA== 
</a> 

但Chrome警示此消息:

Chrome Message

查詢字符串是否無效?我該如何解決它?

BTW:
我的應用程序是在C#和MVC3

+0

[非標準的Web地址格式](可能重複http://stackoverflow.com/questions/1788558/non-standard-web-address-format ) – nemesv

+0

[在URL中傳遞base64編碼的字符串]可能的重複(http://stackoverflow.com/questions/1374753/passing-base64-encoded-strings-in-url) – pixel

回答

2

您應該對URL編碼confirm參數。你得到的錯誤是因爲最後的==片段。

爲此使用HttpServerUtility.UrlEncode或類似的框架方法。

+0

我有用戶Url.Encode和確認查詢字符串已更改爲'?confirm = Y0tcmGepe7wjH7A1CT1IaA%3d%3d',但Google會再次發出相同的消息! –

+0

我遇到了「+」符號被解釋爲空格的問題,因此我必須自己替換三個不安全的base64字符,請參閱:https://stackoverflow.com/a/48441540/236008 –

1

你或許應該URL編碼,因爲=參數值本身被用於參數名稱從參數值分開。

0

//您可以通過更換兩個char「+」到「_」和「/」送你的價值「 - 」

string confirm=confirm.Replace('+', '_').Replace('/', '+'); 

<a target="_blank" href="http://localhost:2817/[email protected]"> 
http://localhost:2817/[email protected] 
</a> 

//你可以通過使用獲得服務器端數據

if (Request.QueryString["confirm"] != null && Request.QueryString["confirm"].ToString() != "") 
{ 
     string confirm = HttpUtility.HtmlDecode(Request.QueryString["confirm"]).Replace('_', '+').Replace('-', '/'); 
} 
0

我用HttpUtility.UrlEncode但如果base64編碼字符串包含一個「+」號,我有問題。它被正確編碼爲「%2b」,但是當它從瀏覽器返回時被解釋爲空間。所以,我用了兩個簡單的編碼/解碼方法,而不是:

public static string UrlEncodeBase64(string base64Input) 
{ 
    return base64Input.Replace('+', '.').Replace('/', '_').Replace('=', '-'); 
} 

public static string UrlDecodeBase64(string encodedBase64Input) 
{ 
    return encodedBase64Input.Replace('.', '+').Replace('_', '/').Replace('-', '='); 
}