【发布时间】:2021-10-22 14:51:36
【问题描述】:
我正在尝试在 ASP.NET 中加密 URL 参数 ID。我用IDataProtector 构建了一个简单的项目。
但我在示例代码中指向的行中收到 Null 引用错误。
控制器:
private readonly IDataProtector protector;
public QRScanningController(IDataProtectionProvider dataProtectionProvider, DataPro dataPro)
{
protector = dataProtectionProvider.Create(dataPro.EmpIdRoutValue);
}
public QRScanningController()
{
//protector = dataProtectionProvider.Create(dataPro.EmpIdRoutValue);
}
public ActionResult Index()
{
DataPro dataProobj = new DataPro();
dataProobj.id = 12131;
dataProobj.encID = protector.Protect(Encoding.ASCII.GetBytes(dataProobj.id.ToString())); **//the issue in this line return Null value.**
return View(dataProobj);
}
public ActionResult QRscan(string encID)
{
return View();
}
【问题讨论】:
-
你没有提到错误是什么。还有
DataPro dataProobj = new DataPro();ID 在哪里设置? -
尊敬的 Rahatur 感谢您的回复,代码中作为注释提到的问题,请查看代码,问题返回 null ,DataPro 是模型类
-
我可以看到创建对象后没有分配ID属性。能否确认
dataProobj.id.ToString()不为空? -
我调试dataProobj.id.ToString()返回12131,dataProobj.encID行的问题,程序停在这里
标签: c# asp.net asp.net-mvc encryption qr-code