【问题标题】:A potentially dangerous Request.Path value was detected from the client (&) on button click单击按钮时从客户端 (&) 检测到潜在危险的 Request.Path 值
【发布时间】:2013-08-31 15:54:54
【问题描述】:

我必须在单击按钮时重定向到控制器操作,但出现此错误

 `A potentially dangerous Request.Path value was detected from the client (&).` 

这是我的代码:

视图/_Layout.cshtml

    <body>
        <div id="wrapper">
            <div id="tab1">
                <div class="tab2">
                    <div id="test2" class="officebar">
                        <ul>
                            <li class="current"><a href="#" rel="home">Main</a>
                                <ul>


 // ..other button code..
                          <li><span>Logout</span> 
                           <div class="button"> 
                            <a href="#" id="Logout"  title="Logout">
                                                <div class="logout">
                                                </div>
                                                Logout</a>
                                        </div>
                                       </li></ul></li>

 <script>

    $("#Logout").click("click", function () {
                    //window.refresh("./Account/Logoutview");
                   // "@Url.Action("Logoutview", "Account")";
                    window.location = "@Url.Action("Logoutview", "Account")";
                 window.location.href = "@Url.Action("Logoutview", "Account")";

                });

 </script>

这是我的注销视图位置:

Views/Account/Logoutview

这是我的输出错误,请帮助:

编辑3:

如果我使用,我可以点击操作方法

<li>
<div><a class="button" href="@Url.Action("Logoutview", "Account")"  title="Logout">Logout</a>
 </div></li>

但我需要使用上面提到的设计。这是问题所在。

解决方案:我试过window.location.href = 'Account/Logoutview';而不是window.location.href = "@Url.Action("Logoutview", "Account")"; 感谢用户 2110309、PKKG、MMohamad Bataineh 抽出宝贵时间 :)

【问题讨论】:

  • 你能展示你的视图生成的源代码吗?我想看看你的那些 Url.Actions 的代码是怎么生成的?
  • 检查我在问题中的编辑
  • 您也可以为您的 LogOut 操作添加代码吗?
  • 尝试使用[ValidateInput(false)] 作为您的操作方法。
  • @PKKG [ValidateInput(false)] 没有解决问题。 :(

标签: jquery asp.net-mvc buttonclick


【解决方案1】:

试着把它放在你的 web.config 中

<system.web>
    <httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
    <pages validateRequest="false" />
</system.web>

如果您没有正确转义数据,这可能会给您的应用程序带来风险。我建议将&amp; 符号替换为另一个字符,例如_

除此之外,我会尝试将[ValidateInput(false)] 放在您的操作之上。你说它对你不起作用,但你可能把它放在了错误的操作上。

【讨论】:

  • 我提出了另一个建议,即只替换 & 符号。他也可以对其进行编码。除此之外,我不明白为什么 [ValidateInput(false)] 不起作用。
  • 请检查我的编辑。
  • @gs11111 您是否尝试将 ValidateInput 放在 Account 中的 LogoutView 操作上方
  • 是的 Mohamad Bataineh,仍然是同样的错误。但是当我使用edit3代码时工作
  • 向我们展示LogOutView 的代码。也只是一个狂野的输入,尝试关闭页面的缓存。
猜你喜欢
  • 2012-04-06
  • 2017-10-07
  • 2011-08-06
  • 2011-08-23
  • 1970-01-01
  • 1970-01-01
  • 2019-04-04
相关资源
最近更新 更多