如何加密查询字符串参数MVC 5 [英] How to encrypt query string parameters MVC 5

查看:94
本文介绍了如何加密查询字符串参数MVC 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已实施加密使用此链接

[ ^ ]



我想要的就像@ Html.ActionLink(详细信息,详细信息,新{id = item.StudentID})但他们使用@ Html.EncodedActionLink(item.QuestionText,Index,Answer,new {questionId = item.QuestionID},null)



我是什么尝试过:



使用此链接https://dotnettrace.net/2013/09/19/encrypt-and-decrypt-url-in- mvc-4 /







@ Html.EncodedActionLink(编辑,员工,新{id = item.StudentID},null)



@ Html.ActionLink(详细信息,详细信息,新{id = item.StudentID})|

@ Html.ActionLink(删除 ,删除,新{id = item.StudentID})

i have implemented encryption using this link
[^]

what i wanted to this like @Html.ActionLink("Details", "Details", new { id=item.StudentID }) but they used @Html.EncodedActionLink(item.QuestionText, "Index", "Answer", new { questionId = item.QuestionID }, null)

What I have tried:

using this link https://dotnettrace.net/2013/09/19/encrypt-and-decrypt-url-in-mvc-4/



@Html.EncodedActionLink( "Edit", "Employee", new { id = item.StudentID }, null)

@Html.ActionLink("Details", "Details", new { id=item.StudentID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.StudentID })

推荐答案

由于您发现难以关注链接中的文章,我只是为您简单。

作者积分:



按照以下步骤操作:

步骤1:

在项目中创建一个新的类文件( somename.cs ),然后复制粘贴来自这个 [ ^ ],我试着粘贴代码在这里,它没有正确粘贴。

所以你可以将somename.cs文件中的现有代码替换为链接中可用的代码。



第2步:

建立一次项目。

第3步:

在你发布这段代码的评论中

Since you finding difficult to follow the article in link, i am just making it simple for you.
Credits to the Author:

Follow the below steps:
Step 1:
Create a new class file (somename.cs) in you project and just copy paste the code from this[^], i tried pasting the code over here, it is not pasting properly.
so you can just replace the existing code in somename.cs file to the code which is available in the link.

Step 2:
Build your project once.
Step 3:
in the comments you have posted this piece of code
@Html.EncodedActionLink(item.StudentName, "Edit", "Employee", new { id = item.StudentID }, null)



因此控制器名称为Employee,Action为Edit

转到EmployeeController - >编辑操作并将 [EncryptedActionParameter] 属性添加到操作中,如下所示




So the Controller Name is "Employee" and the Action is "Edit"
Go to EmployeeController -> Edit Action and add the [EncryptedActionParameter] attribute to the action as below

 [EncryptedActionParameter]
 public ActionResult Edit(int? Id)
 {
// your code...
  }





现在应该可以了。

注意:在作者使用以下密钥进行加密/解密的文章中,您可以将其更改为你的需要。



Now it should work.
Note: In the article the author has used the below key for Encryption/Decryption, you can change it for your need.

string key = "jdsg432387#";


这篇关于如何加密查询字符串参数MVC 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆