2013-04-12 32 views
4

我有這個網址這工作絕對沒我的VS Web服務器上MVC4:URL的電子郵件路由作爲參數

http://localhost:4454/cms/account/edituser/[email protected] (works) 

但是當我發佈這個網站IIS7.5,它只是拋出404

http://dev.test.com/cms/account/edituser/[email protected] (does not work) 

但奇怪的事情發生,如果我刪除的電子郵件地址

http://dev.test.com/cms/account/edituser/email (works , no 404) 

,但如果我改變我的網址查詢字符串,它工作正常

http://dev.test.com/cms/account/[email protected] (works) 

這裏是我的路由條目

routes.MapRoute(
      "Default", // Route name 
      "{controller}/{action}/{id}", // URL with parameters 
      new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults 
      new[] { "App.NameSpace.Web.Controllers" } 
     ); 

我已經注意到奇怪的是,當服務器拋出404錯誤頁面,這是一個標準的iis 404頁,而不是一個自定義的我。
所以我想知道是否有任何問題與我的路線映射 或IIS不喜歡有電子郵件作爲參數的網址。但一切工作正常與我的本地開發。
謝謝

回答

7

嘗試使用URL編碼URL中的電子郵件地址。

編輯

以UrlEncode + Base64編碼?

public static string ToBase64(this string value) 
    { 
     byte[] bytes = Encoding.UTF8.GetBytes(value); 
     return Convert.ToBase64String(bytes); 
    } 

    public static string FromBase64(this string value) 
    { 
     byte[] bytes = Convert.FromBase64String(value); 
     return Encoding.UTF8.GetString(bytes); 
    } 

在你看來:

<a href="@Url.Action("MyAction", new { Id = email.ToBase64() })">Link</a> 

在你的控制器

function ActionResult MyAction(string id){ 
    id = id.FromBase64(); 
    //rest of your logic here 
} 
+0

謝謝@Raciel。 MVC自身編碼就像電子郵件%40domian.com – Nnp

+0

Base64 + UrlEncode應該給你你需要的東西。 –

+0

在哪裏添加ToBase64和FromBase64函數? –

4

[email protected]包含不路徑的法律一部分的字符(有很好的理由,他們往往保留特殊功能)。您需要引用/ url編碼這些字符或將它們傳遞給查詢字符串。

Scott Hanselman有一個great post允許「淘氣的東西」的網址。

相關問題