2011-06-28 141 views

回答

2

我會使用查詢字符串參數建議你,也確保值正確的URL編碼:

http://website/controller/method?url=http%3A%2F%2Fotherurl.com 

和行動中:

public ActionResult Method(string url) 
{ 
    // The url parameter here will equal to "http://otherurl.com" 
    ... 
} 
0

網址由兩個部分組成,第一部分是域(我認爲),這裏重要的是第二部分被稱爲查詢字符串。 (第一部分是強制性的,第二部分不是)。

這是一個例子:

http://your-domain-here/stuff?page=1 

現在page是一個查詢字符串變量。你必須注意到?它分開了Url的兩個部分,我沒有在你的URL中看到一個,因此IMO,MVC路由引擎會嘗試將這個整個Url與註冊路由(不會被找到)匹配。

不,我會說,你沒有當我們需要一個新的「路徑」,但在你的情況,你只需要提高URL分開來創建一個新途徑,創建新航線關閉查詢字符串的路由。

希望有所幫助。

0

你將不得不創建另一條路線, 是這樣的:

routes.MapRoute("UrlByParam", //Route Name 
"{controller}/{action}/{url}", //Url Pattern 
new { controller = "DefaultController", action = "DefaultAction" }); //Defaults 

,你也有編碼您的網址, 所以,

http://website/controller/method/http://otherurl.com 

將成爲

http://website/controller/method/http%3A%2F%2Fotherurl.com