获取一个完整的url,例如http://google.com作为操作输入
我希望在我的操作中获取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); }
通过添加Update2
问题没解决! 🙁
最后错误已解决,但url从http://google.com
更改为http:/google.com
,我在这里要求它,我得到了答案。
尝试将requestPathInvalidCharacters
属性添加到httpRuntime
默认值为<,>,*,%,&,:,\,?
您可以禁用自动请求validation。
在web.config中:
或采取行动:
[ValidateInput(false)] public ActionResult PR(...
我忘记了web.config。 您需要添加到web.config:
或者你可以编码/解码url