【问题标题】:Getting error while clicking on link单击链接时出现错误
【发布时间】:2014-09-16 12:12:15
【问题描述】:

我正在使用淘汰赛的 observable 将 url 动态绑定到我的 href 标记

 <a data-bind="attr: { href: URlPath }">See this</a>

我已经声明 observable 如下

       this.URlPath = ko.observable("http://mysite/api/MyMethod&Param1=0000333&Param2=0000000002&Param3=0000000001");

当我点击链接时出现错误

A potentially dangerous Request.Path value was detected from the client (&). 
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (&).]
System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9561124
System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53

我尝试在 web.config 中使用下面但没有帮助。我正在使用 WebApi。

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

我也没有任何特殊字符,但我仍然收到此错误。有人可以帮我吗?

更新

这是我在 webapi 中的方法

[ActionName("MyMethod")]
[AcceptVerbsAttribute("GET", "POST")]
[HttpPost]
public HttpResponseMessage MyMethod(string Param1, string Param2, string Param3)
{
      //some logic
}

【问题讨论】:

  • 你用谷歌搜索过那个错误吗?它有很多结果。 Top Result
  • @xdumaine 我尝试在 webpi 控制器上使用 [ValidateInput(false)] 但似乎它不允许我。我得到语法错误

标签: asp.net asp.net-web-api


【解决方案1】:

你的url错了应该如下you are using &amp; after Action Name

this.URlPath = ko.observable("http://mysite/api/MyMethod?Param1=0000333&Param2=0000000002&Param3=0000000001");

【讨论】:

  • 是的,你是对的。只是错过了“?”我也不想在用户点击链接时向他显示参数。我该如何避免呢?
  • 创建一个模型并将该模型发送到 web api。但有些工具可以破解数据,比如提琴手
  • 你能给我举个例子吗?我会很感激的。没关系,如果它在提琴手中被黑了,那也没关系。我只是不让普通用户查看参数
猜你喜欢
  • 2014-05-10
  • 1970-01-01
  • 1970-01-01
  • 2012-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多