3

我想在我的操作中获取 url 以返回页面的 PageRank。我有这样的路线:

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)]了,但没有解决问题!动作是这样的:

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

通过 添加更新2

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

问题没有解决!:(

终于 错误解决了,但是 url 从http://google.comto变成了,我在这里http:/google.com问了,我得到了答案。

4

2 回答 2

2

尝试添加一个requestPathInvalidCharacters属性httpRuntime

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

默认值为&lt;,&gt;,*,%,&amp;,:,\,?

于 2012-08-07T04:22:44.247 回答
1

您可以禁用自动请求验证。

在 web.config 中:

<pages validateRequest="false">

或采取行动:

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

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

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

或者您可以编码/解码网址

于 2012-08-07T03:30:37.960 回答