允许具有多个句点的路径ID

时间:2013-03-05 20:47:35

标签: c# asp.net-mvc-4

如何在网址中允许多个句点?

示例网址:

http://mylocalhost:6968/MyHome/Edit/ABCD.Applications.ClinicalData%257cCache_Timeout

我试过了:

各种网址编码:

       @{
            //string encodedItem = Url.Encode(item.Key);
            //string encodedItem = HttpUtility.UrlEncode(item.Key);                
            string encodedItem = Server.UrlEncode(item.Key);
        }

Adding路由处理程序:

<add name="UrlRoutingHandler" type="System.Web.Routing.UrlRoutingHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" path="Remote.mvc/*" verb="GET"/>

Modifying web.config system.web

<httpRuntime relaxedUrlToFileSystemMapping="true" />

这些都没有更正示例网址。

相关代码

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Key)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Value)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.IsActive)
        </td>
        <td>
            @{
                //string encodedItem = Url.Encode(item.Key);
                //string encodedItem = HttpUtility.UrlEncode(item.Key);                
                string encodedItem = Server.UrlEncode(item.Key);                
            }
            @Html.ActionLink("Edit", "Edit", new {  id = encodedItem }) |
            @Html.ActionLink("Details", "Details", new {  id = encodedItem }) |
            @Html.ActionLink("Delete", "Delete", new {  id = encodedItem })
        </td>
    </tr>
}

我点击了编辑链接。

我也试过

@Html.ActionLink("Edit", "Edit", new { id = item.Key })

的html输出为:

a href=/MyHome/Edit/ABCD.Applications.ClinicalData%7CCache_Timeout

点击此链接会导致错误:

HTTP Error 404.0

我在Controller.Edit设置了一个断点。断点永远不会被击中。我有任何形式的网址:

http://mylocalhost:6968/MyHome/Edit/ABCD.X

如果X是.之后的任何内容,则会发生此错误。如果我删除X,则会触发断点。

1 个答案:

答案 0 :(得分:0)

HTTP GET被证明是不可能的。我决定重新设计解决方案。现在我执行 HTTP POST 以避免通过URL传递数据。

理想情况下,我的网址为hackable。但它是一个内部应用程序及其客户想要的东西......嘿小子,小心碎玻璃

相关问题