加密@Html.ActionLink 中的参数

问题描述

我正在尝试从 asp.net razor

加密我的 url id

在我看来,我有以下@Html.ActionLink

@Html.ActionLink(" ","index","Home",new { id = Server.UrlEncode(item.ID.ToString()) },new { @class = "fas fa-eye",@title = "Ver Detalle" })

我得到的链接如下:

http://localhost:62201/Home/index/1

这个想法是为了“更安全”隐藏或加密 id,就像这样:

http://localhost:62201/Home/index/unrecognizable_id

然后在我的 controller

中解码

我提前感谢您的帮助。

解决方法

如果你想隐藏Id,你可以尝试使用form post:

@using (Html.BeginForm("index","Home",FormMethod.Post))
{
    <input hidden name="Id" value=@item.ID />
    <input type="submit" value="submit" />
}

结果: enter image description here

另外,如果要使用加密,可以参考link