Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

asp.net mvc - encrypt parameters in @Html.ActionLink

i am trying to encrypt my url id from asp.net razor

In my view I have the following @Html.ActionLink:

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

With that I get the link as follows:

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

And the idea is to hide or encrypt the id for "more security", something like this:

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

And then this is decoded in my controller

I appreciate your help in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you want to hide the Id,you can try to use form post:

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

result: enter image description here

In addition,If you want to use encrypt,you can refer to the link.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...