2012-08-07 21 views
3

我想在我的操作中獲取網址以返回網頁的PageRank。我有這樣的路線:獲取像http://google.com一樣的完整網址作爲操作輸入

routes.MapRoute(
    name: "PRURL", 
    url: "Utility/PR/{*url}", 
    defaults: new { controller = "Utility", action = "PR", url = UrlParameter.Optional } 
); 

但每當我去http://localhost:1619/Utility/PR/http://google.com我只是得到一個System.Web.HttpException告訴我A potentially dangerous Request.Path value was detected from the client (:).我想解決這個問題,但我不知道怎麼辦!

有人可以幫我嗎?


更新

我試圖[ValidateInput(false)]但它並沒有解決這個問題! 動作是這樣的:通過添加

<system.web> 
    <httpRuntime requestValidationMode="2.0" /> 
</system.web> 

問題沒有解決

[ValidateInput(false)] 
public string PR(string url) 
{   
    return GooglePageRank.PRChecker.PR(url); 
} 

UPDATE2 ! :(

終於 錯誤解決,但該網址從http://google.com改爲http:/google.com,我問它here,我得到了答案。

+0

看看這個http://stackoverflow.com/questions/6025522/getting-a-potentially-dangerous-request-path-value-was-detected-from-the-client – Charlie 2012-08-07 04:16:21

回答

2

嘗試將requestPathInvalidCharacters屬性添加到httpRuntime

<httpRuntime requestValidationMode="2.0" 
    requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\,?" /> 

的默認值是&lt;,&gt;,*,%,&amp;,:,\,?

+0

謝謝。它工作正常,但http://google.com更改爲http:/google.com。我會問一個問題。 – 2012-08-07 19:44:53

1

您可以禁用自動請求的確認。

在網頁的.config:

<pages validateRequest="false"> 

或者行動:

[ValidateInput(false)] 
public ActionResult PR(... 

而我忘了web.config。您需要添加到web.config中:

<system.web> 
    <httpRuntime requestValidationMode="2.0" /> 
</system.web> 

或者你可以編碼/解碼網址

+0

謝謝小號!但如果我只想做一個動作呢? – 2012-08-07 03:31:16

+0

和我在哪裏添加這個? – 2012-08-07 03:34:37

+0

我已經使用'[ValidateInput(false)]'禁用了'ValidateInput',但我仍然得到安全異常! – 2012-08-07 03:37:24